I'm writing a simple WMI query in the powershell ISE. I want to get just two fields, but I get more
Get-WmiObject -Query "select DisplayName, State from Win32_Service"
And what I get is a list of results, each has the next fields,
__GENUS : 2
__CLASS : Win32_Service
__SUPERCLASS :
__DYNASTY :
__RELPATH :
__PROPERTY_COUNT : 2
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
DisplayName : Windows Font Cache Service
State : Running
I noticed that the fields all start with a double underscore, not sure if it means anything. I know I can get a better result with
Get-WmiObject -Class Win32_Service | Select-Object DisplayName, State
However, I would like to add a where clause to this query, so I'm trying to use the -Query option.
get-wmiobject -query "select DisplayName, State from Win32_service WHERE ..." | select-object DisplayName, State- Tomalakget-wmiobject -class win32_service | where-object -Property State -EQ -Value "Stopped" | select-object DisplayName, State. - Andrew MortonGet-WmiObject's format file that dictates how objects from that cmdlet get printed to the console. You would either have to manually edit that, or the easy way is to just use theSelect-Objectcmdlet. - Maximilian Burszley