Leveraging WMI (Part 4)

by Apr 22, 2022

The secret to successfully leveraging WMI is knowing the class names that represent what you are after. In the previous tip we explained how to use IntelliSense to ask Get-CimInstance for available class names. You can do the same programmatically, too, though. Below is code that dumps all valid WMI class names for the default namespace rootcimv2:

Get-CimClass | Select-Object -ExpandProperty CimClassName | Sort-Object

To check whether a given class name really represents what you are looking for, do a test query. For example, to get all instances of Win32_OperatingSystem, run this:

 
PS> Get-CimInstance -ClassName Win32_OperatingSystem

SystemDirectory     Organization BuildNumber RegisteredUser SerialNumber            Version   
---------------     ------------ ----------- -------------- ------------            -------   
C:WINDOWSsystem32 psconf.eu    19042       Zumsel         12345-12345-12345-AAOEM 10.0.19042   
 

Some WMI class names are obvious but others are not. To get a peek preview of the properties found in any given class name, try this:

Get-CimClass | 
Select-Object -Property CimClassName, @{
N='Properties'
E={$_.CimClassProperties -join ','}
} | 
Out-GridView -PassThru

The result is a grid view window showing the WMI class names and their property names. Now you can use the text box filter at the top of the grid view window to filter for any keyword. Only the lines that contain your keyword in either WMI class name or one of its properties are listed.

Select the class(es) you find interesting, and click OK in the bottom left corner to output the information to the console. Next, you can use Get-CimInstance to test query the WMI class names you found.


Twitter This Tip! ReTweet this Tip!