Summary: Learn how to locate the right WMI class by using the Get-CimClass cmdlet to work through the class schema. Windows Management Instrumentation (WMI) came into the Windows world around the time of the Windows NT 4.0 Service Pack 4—that’s about the same time as the release of Star Wars 1: The Phantom Menace. One of the really cool things about WMI was that I could (with some difficulty) write VBScript scripts that accessed the WMI schema. Therefore, I could use script to search through the WMI classes to help me locate and find information that I would later use in other VBScript scripts. In this way, it was self-describing, and it pointed the way forward to Windows PowerShell.
Nearly twenty years later, another Star Wars movie released (with another on the horizon), and we have Windows PowerShell. We can still do schema queries, but now we can do it in a single line, ad-hoc style, instead of two page scripts that take weeks to develop.
To use CIM cmdlets to find WMI classes, the first thing I need to know how to list all of the WMI classes in my current namespace. This is very simple. I use the Get-CimClass cmdlet with nothing else. Here is the command and output:
This is not particularly illuminating, but it is an important first step.
I like to find WMI classes that have methods. As shown in the previous image, there are lots of WMI classes that do not have methods and only a few that do have methods.
Note Introduced in Windows 8, quite a few methods were added to previously existing WMI classes. In addition, several new WMI providers were added, which increase the scope of what we can do from a management perspective.
The cool thing is that I can add the MethodName parameter to my Get-CimClass query so I can find methods. It will accept wildcard characters, so if I have an idea of what I want to do, but I do not know either the WMI class or the actual method name, I can still find it. Here I look for something that will start something:
Get-CimClass -MethodName start*
Here is the command and its output:
There are a lot of similar looking class names. So I want to filter out the abstract classes. I can do this by adding Dynamic as a qualifier:
Get-CimClass -MethodName start* -QualifierName dynamic
I can now compare my two queries. The results are shown here:
I can make this clearer by adding the Abstract qualifier to my query:
Get-CimClass -MethodName start* -QualifierName abstract
Now I can compare my Dynamic and Abstract classes, as shown here:
Join me tomorrow when I’ll will explore this a bit further.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at firstname.lastname@example.org, 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