{"id":77072,"date":"2016-02-12T00:01:22","date_gmt":"2016-02-12T00:01:22","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=77072"},"modified":"2019-02-18T09:19:54","modified_gmt":"2019-02-18T16:19:54","slug":"finding-wmi-classes-that-contain-methods","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/finding-wmi-classes-that-contain-methods\/","title":{"rendered":"Finding WMI classes that contain methods"},"content":{"rendered":"<p><strong>Summary<\/strong>: Learn how to find methods from WMI classes.<\/p>\n<p>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:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/H1.jpg\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-77091\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/H1-300x190.jpg\" alt=\"Photo of sign\" width=\"300\" height=\"190\" \/><\/a><\/p>\n<p>But by using the CIM cmdlets, we can bring a bit of order to an otherwise messy situation.<\/p>\n<p>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 <strong>*<\/strong>, my command will return all WMI classes that have a method defined:<\/p>\n<p style=\"padding-left: 30px\">Get-CimClass -MethodName *<\/p>\n<p>The command and output from the command are shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-12-16-01.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-77101\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-12-16-01-300x179.png\" alt=\"Image of command output\" width=\"300\" height=\"179\" \/><\/a><\/p>\n<p>Even with tab expansion, typing <strong>Get-CimClass<\/strong> is a bit annoying. Luckily, there is an alias. I found the alias by using the <strong>Get-Alias<\/strong> cmdlet:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Alias -Definition get-cimclass<\/p>\n<p style=\"padding-left: 30px\">CommandType\u00a0\u00a0\u00a0\u00a0 Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Version\u00a0\u00a0\u00a0 Source<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212;&#8212;&#8211;\u00a0\u00a0\u00a0\u00a0 &#8212;-\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8212;&#8212;-\u00a0\u00a0\u00a0 &#8212;&#8212;<\/p>\n<p style=\"padding-left: 30px\">Alias\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 gcls -&gt; Get-CimClass<\/p>\n<p>Now I want to find all <strong>Dynamic<\/strong> classes that have methods defined. I use the following command (<strong>glcs<\/strong> is the alias for <strong>Get-CimClass<\/strong>):<\/p>\n<p style=\"padding-left: 30px\">gcls\u00a0 -MethodName * -QualifierName dynamic<\/p>\n<p>Here are the command and the output from the command:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-12-16-02.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-77111\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-12-16-02-300x179.png\" alt=\"Image of command output\" width=\"300\" height=\"179\" \/><\/a><\/p>\n<p>How many classes with methods is this anyway? I pipe the output to the <strong>Measure-Object<\/strong> cmdlet (<strong>measure<\/strong> is an alias):<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; gcls\u00a0 -MethodName * -QualifierName dynamic | measure<\/p>\n<p style=\"padding-left: 30px\">Count\u00a0 \u00a0\u00a0: 110<\/p>\n<p style=\"padding-left: 30px\">Average\u00a0 :<\/p>\n<p style=\"padding-left: 30px\">Sum\u00a0\u00a0\u00a0\u00a0\u00a0 :<\/p>\n<p style=\"padding-left: 30px\">Maximum\u00a0 :<\/p>\n<p style=\"padding-left: 30px\">Minimum\u00a0 :<\/p>\n<p style=\"padding-left: 30px\">Property :<\/p>\n<p>How many dynamic WMI classes are there?<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; gcls\u00a0 -QualifierName dynamic | Measure-Object<\/p>\n<p style=\"padding-left: 30px\">Count\u00a0\u00a0\u00a0 : 634<\/p>\n<p style=\"padding-left: 30px\">Average\u00a0 :<\/p>\n<p style=\"padding-left: 30px\">Sum\u00a0\u00a0\u00a0\u00a0\u00a0 :<\/p>\n<p style=\"padding-left: 30px\">Maximum\u00a0 :<\/p>\n<p style=\"padding-left: 30px\">Minimum\u00a0 :<\/p>\n<p style=\"padding-left: 30px\">Property :<\/p>\n<p>Well, that is pretty cool. So what are the most common method names? I can expand the <strong>CimClassMethods<\/strong> property and group the output. Following is the command I came up with:<\/p>\n<p style=\"padding-left: 30px\">gcls\u00a0 -MethodName * -QualifierName dynamic | select -ExpandProperty cimclassmethods | group | sort count -Descending<\/p>\n<p>Here is the command and the output from the command:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-12-16-03.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-77081\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-2-12-16-03-300x259.png\" alt=\"Image of command output\" width=\"300\" height=\"259\" \/><\/a><\/p>\n<p>I have found some interesting methods. Now I want to know what cmdlets have the <strong>GetRecordCount<\/strong> method, so I use the following command:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; gcls\u00a0 -MethodName getrecordcount<\/p>\n<p style=\"padding-left: 30px\">\u00a0\u00a0 NameSpace: ROOT\/cimv2<\/p>\n<p style=\"padding-left: 30px\">CimClassName\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CimClassMethods\u00a0\u00a0\u00a0\u00a0\u00a0 CimClassProperties<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212;&#8212;&#8212;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8212;&#8212;&#8212;&#8212;&#8212;\u00a0\u00a0\u00a0\u00a0\u00a0 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p style=\"padding-left: 30px\">Win32_ReliabilityStabilityMetrics\u00a0\u00a0 {GetRecordCount}\u00a0\u00a0\u00a0\u00a0 {EndMeasurementDate, Rel&#8230;<\/p>\n<p style=\"padding-left: 30px\">Win32_ReliabilityRecords\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {GetRecordCount}\u00a0\u00a0\u00a0\u00a0 {ComputerName, EventIden&#8230;<\/p>\n<p>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.<\/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 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 [&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-77072","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 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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/77072","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=77072"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/77072\/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=77072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=77072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=77072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}