Question

In Powershell I run a get-wmiobject on Win32_OperatingSystem, and it returns several properties through the select-object cmdlet. How to I get the values loaded to variables instead of a list,since I need to further process them? I tried several methods without avail. If I can get this accomplished without the select-object cmdlet, that would also work.

get-wmiobject -namespace root\CIMV2 -class Win32_OperatingSystem -computername $servername | Select-Object SystemDirectory,caption,BuildNumber
Was it helpful?

Solution

It seems you know how to assign variables, so I'm not sure what the hang up is here. You would simply run the GWMI command as the value of a variable such as:

$Results = get-wmiobject -namespace root\CIMV2 -class Win32_OperatingSystem -computername $servername

Then reference the properties of the object you just created such as:

$Results.SystemDirectory
$Results.caption
$Results.BuildNumber
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top