Skip to main content
Question

Powershell Issue "You cannot call a method on a null-valued expression" Extended Attribute


Forum|alt.badge.img+8

Hi All,

I need some help with this. I am trying to capture the Site Name via API (don't ask me why I have my reasons) Ofcourse with a bash shell no problems but as we do have some windows systems I would like to have it done for those computers as well. So I created a powershell script which should do the trick.

When I run this script on the windows machine I have a result like:
<result>sitename</result>

When I run this via the recon I get : "You cannot call a method on a null-valued expression"

When I google this error I get results get a variable is not set.. Just can't see which one..

Any Ideas?

$computername = Get-WMIObject Win32_ComputerSystem | Select-Object -ExpandProperty name
$url = "https://jss.xxxx:8443/JSSResource/computers/name/$computername"
$username = "xxxx"
$password = "xxxxxx"
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($username, $password)
[xml]$webpage = $webclient.DownloadString($url)

$sitename = $webpage.SelectNodes("//computer/general/site")

$result = $sitename.OuterXml.Split('><')[8]

echo "<result>$result</result>"

0 replies

Be the first to reply!

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings