Summary: Learn how to find methods from WMI classes.
Sometimes when working with WMI, it might seem as if you are entering a strange territory with dangers lurking around every corner. Unfortunately, there might not even be a sign such as the following to alert you to the hidden dangers:
But by using the CIM cmdlets, we can bring a bit of order to an otherwise messy situation.
If I do not know the name of a WMI method, I can use a wildcard character to find the method. If I use the *, my command will return all WMI classes that have a method defined:
Get-CimClass -MethodName *
The command and output from the command are shown here:
Even with tab expansion, typing Get-CimClass is a bit annoying. Luckily, there is an alias. I found the alias by using the Get-Alias cmdlet:
PS C:\> Get-Alias -Definition get-cimclass
CommandType    Name                                              Version   Source
———–Â Â Â Â —-Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ——-Â Â Â ——
Alias          gcls -> Get-CimClass
Now I want to find all Dynamic classes that have methods defined. I use the following command (glcs is the alias for Get-CimClass):
gcls -MethodName * -QualifierName dynamic
Here are the command and the output from the command:
How many classes with methods is this anyway? I pipe the output to the Measure-Object cmdlet (measure is an alias):
PS C:\> gcls -MethodName * -QualifierName dynamic | measure
Count   : 110
Average :
Sum     :
Maximum :
Minimum :
Property :
How many dynamic WMI classes are there?
PS C:\> gcls -QualifierName dynamic | Measure-Object
Count   : 634
Average :
Sum     :
Maximum :
Minimum :
Property :
Well, that is pretty cool. So what are the most common method names? I can expand the CimClassMethods property and group the output. Following is the command I came up with:
gcls -MethodName * -QualifierName dynamic | select -ExpandProperty cimclassmethods | group | sort count -Descending
Here is the command and the output from the command:
I have found some interesting methods. Now I want to know what cmdlets have the GetRecordCount method, so I use the following command:
PS C:\> gcls -MethodName getrecordcount
  NameSpace: ROOT/cimv2
CimClassName                       CimClassMethods     CimClassProperties
————Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â —————Â Â Â Â Â ——————
Win32_ReliabilityStabilityMetrics  {GetRecordCount}    {EndMeasurementDate, Rel…
Win32_ReliabilityRecords           {GetRecordCount}    {ComputerName, EventIden…
By using these techniques, I can find exactly the WMI class I need with the method I want to use to help take my management skills to the next level. Try it out. It is kind of fun and extremely powerful. Anyway, it is better than walking around with a can of bear spray.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. Also check out my Microsoft Operations Management Suite Blog. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy
0 comments