Search code examples
powershellget-wmiobject

Filtering Get-WmiObject Class Property Output to include only value


I've been utilizing Powershell to query items from a host using the "Get-WmiObject" cmdlet and the associated classes as part of a script. In order to find the Computer Manufacturer I use the following Get-WMIObject command to output the returned property to a variable:

PS C:\temp\PS> $VmPhys = Get-WmiObject -Class Win32_ComputerSystem |Select-Object -Property Manufacturer
PS C:\temp\PS> write-host = $VmPhys
= @{Manufacturer=Dell Inc.}

The issue I have is that when I send the property value to the variable it also includes the property name and not just the value as per the above.

PS C:\temp\PS> Get-WmiObject -Class Win32_ComputerSystem |Select-Object -Property Manufacturer

Manufacturer
------------
Dell Inc.

Is there a way to exclude the property name and only export the value eg "Dell Inc." to the variable?


Solution

  • Use -Expandproperty instead of property

    Get-WmiObject -Class Win32_ComputerSystem |Select-Object -ExpandProperty Manufacturer