{"id":77011,"date":"2016-02-11T00:01:44","date_gmt":"2016-02-11T00:01:44","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=77011"},"modified":"2019-02-18T09:19:55","modified_gmt":"2019-02-18T16:19:55","slug":"use-cim-cmdlets-to-find-wmi-classes","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-cim-cmdlets-to-find-wmi-classes\/","title":{"rendered":"Use CIM cmdlets to find WMI classes"},"content":{"rendered":"<p><strong>Summary<\/strong>: Learn how to locate the right WMI class by using the <strong>Get-CimClass<\/strong> cmdlet to work through the class schema. <a href=\"https:\/\/en.wikipedia.org\/wiki\/Windows_Management_Instrumentation\" target=\"_blank\">Windows Management Instrumentation<\/a> (WMI) came into the Windows world around the time of the Windows NT 4.0 Service Pack 4\u2014that\u2019s about the same time as the release of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Star_Wars_Episode_I:_The_Phantom_Menace\" target=\"_blank\">Star Wars 1: The Phantom Menace<\/a>. 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.<\/p>\n<p>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.<\/p>\n<p>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 <strong>Get-CimClass<\/strong> cmdlet with nothing else. Here is the command and output:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-11-16-01.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-77042\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-11-16-01-300x179.png\" alt=\"Image of command output\" width=\"300\" height=\"179\" \/><\/a><\/p>\n<p>This is not particularly illuminating, but it is an important first step.<\/p>\n<p>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.<\/p>\n<p style=\"padding-left: 30px\"><strong>Note<\/strong>\u00a0\u00a0\u00a0Introduced in Windows\u00a08, 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.<\/p>\n<p>The cool thing is that I can add the <strong>MethodName<\/strong> parameter to my <strong>Get-CimClass<\/strong> 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:<\/p>\n<p style=\"padding-left: 30px\">Get-CimClass -MethodName start*<\/p>\n<p>Here is the command and its output:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-11-16-02.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-77052\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-11-16-02-300x179.png\" alt=\"Image of command output\" width=\"300\" height=\"179\" \/><\/a><\/p>\n<p>There are a lot of similar looking class names. So I want to filter out the abstract classes. I can do this by adding <strong>Dynamic<\/strong> as a qualifier:<\/p>\n<p style=\"padding-left: 30px\">Get-CimClass -MethodName start* -QualifierName dynamic<\/p>\n<p>I can now compare my two queries. The results are shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-11-16-03.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-77031\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-11-16-03-300x219.png\" alt=\"Image of command output\" width=\"300\" height=\"219\" \/><\/a><\/p>\n<p>I can make this clearer by adding the <strong>Abstract<\/strong> qualifier to my query:<\/p>\n<p style=\"padding-left: 30px\">Get-CimClass -MethodName start* -QualifierName abstract<\/p>\n<p>Now I can compare my <strong>Dynamic<\/strong> and <strong>Abstract<\/strong> classes, as shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-11-16-04.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-77061\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-11-16-04-300x219.png\" alt=\"Image of command output\" width=\"300\" height=\"219\" \/><\/a><\/p>\n<p>Join me tomorrow when I\u2019ll will explore this a bit further.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. Also check out my <a href=\"https:\/\/blogs.technet.microsoft.com\/msoms\/\" target=\"_blank\">Microsoft Operations Management Suite Blog<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2014that\u2019s about the same time as the release of Star Wars 1: The Phantom Menace. One [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[568],"tags":[385,3,45,6],"class_list":["post-77011","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hey-scripting-guy","tag-cim","tag-scripting-guy","tag-windows-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>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\u2014that\u2019s about the same time as the release of Star Wars 1: The Phantom Menace. One [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/77011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=77011"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/77011\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=77011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=77011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=77011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}