{"id":4592,"date":"2012-11-26T00:01:00","date_gmt":"2012-11-26T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/11\/26\/use-powershell-3-0-and-the-cim-cmdlets-to-explore-wmi-classes\/"},"modified":"2012-11-26T00:01:00","modified_gmt":"2012-11-26T00:01:00","slug":"use-powershell-3-0-and-the-cim-cmdlets-to-explore-wmi-classes","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-3-0-and-the-cim-cmdlets-to-explore-wmi-classes\/","title":{"rendered":"Use PowerShell 3.0 and the CIM Cmdlets to Explore WMI Classes"},"content":{"rendered":"<p><strong>Summary:<\/strong> Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell&nbsp;3.0 and the CIM cmdlets to explore WMI classes.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Today, the Scripting Wife and I are on the train from Dortmund to Geneva. Teresa was really smart and found tickets for us to tour the Particle Accelerator at Cern. This is a nice train ride, and in addition to being a great place to work, the scenery outside is wonderful as well.<\/p>\n<p>While in Dortmund, we had time to spend the day with Windows PowerShell Guru Klaus Schulte. In addition to talking about Windows PowerShell, we walked around Dortmund taking pictures. Here is a photo of the Scripting Wife, Klaus, and his wife, Susanne, during our walk.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5582.Hsg-11-26-12-A.jpg\"><img decoding=\"async\" title=\"Photo of Teresa, Klaus, and his wife, Susanne\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5582.Hsg-11-26-12-A.jpg\" alt=\"Photo of Teresa, Klaus, and his wife, Susanne\" \/><\/a><\/p>\n<p>One of the cool things about Dortmund is they have one of the nicest burger places I have ever seen; not that we ate there, but it just looked cool, as shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5824.Hsg-11-26-12-B.jpg\"><img decoding=\"async\" title=\"Photo of burger place\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5824.Hsg-11-26-12-B.jpg\" alt=\"Photo of burger place\" \/><\/a><\/p>\n<p>One of the problems with traveling on a train is how expensive wireless Internet is, and I just do not want to pay that much. This means I am limited to resources on my laptop. In the old days, I used to install the WMI&nbsp;SDK on my laptop so that I would have ready information about the classes. These days the WMI&nbsp;SDK is incorporated with the Windows Platform SDK (or maybe we call it something else), and this takes a whole lot of disk space that I really do not have. Luckily, I do not need to invest this much disk space to just find out things like writable properties or implemented methods of WMI classes. The <strong>Get-CIMClass<\/strong> cmdlet does an excellent job of exposing just the information I need.<\/p>\n<h2>Exploring WMI classes<\/h2>\n<p>Many WMI classes have writable properties. To see these, I need to look for the <strong>write<\/strong> qualifier. Well, I do not exactly have to do this&mdash;I can use the WbemTest utility to find this information. So, I type <strong>WbemTest<\/strong> in my Windows PowerShell console. When WbemTest opens, I have to click <strong>connect<\/strong><em> <\/em>to connect to the root\/cimv2 WMI namespace. Once this connects, I can now click <strong>Open Class<\/strong> and type <strong>Win32_Computersystem<\/strong>, for example. Now I have the Object Editor for Win32_ComputerSystem. I have to look at every single property individually to see the qualifiers. If a property does not possess the <strong>write<\/strong><em> <\/em>qualifier, it is read-only, as shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6523.hsg-11-26-12-01.png\"><img decoding=\"async\" title=\"Image of Property Editor\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6523.hsg-11-26-12-01.png\" alt=\"Image of Property Editor\" \/><\/a><\/p>\n<p>Using the old <strong>Get-WmiObject<\/strong> cmdlets and piping the results to <strong>Get-Member<\/strong> is misleading because it reports all properties as <strong>Get;Set<\/strong> (but I know from WbemTest that the name property is read-only). This is shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-WmiObject win32_computersystem | get-member -Name name<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; TypeName: System.Management.ManagementObject#root\\cimv2\\Win32_ComputerSystem<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Name MemberType Definition<\/p>\n<p style=\"padding-left: 30px\">&#8212;- &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">Name Property&nbsp;&nbsp; string Name {get;set;}<\/p>\n<h2>&nbsp;Using the CIM classes to find WMI Writable properties<\/h2>\n<p>The easy way to find WMI class information is to use the <strong>Get-CimClass<\/strong> cmdlet. For example, to see all of the writable properties from a WMI class, such as the Win32_ComputerSystem WMI class, I can use the following code.<\/p>\n<p style=\"padding-left: 30px\">Get-CimClass win32_computersystem | select -ExpandProperty cimclassproperties |<\/p>\n<p style=\"padding-left: 30px\">where qualifiers -match &#8216;write&#8217; | Format-table name, qualifiers<\/p>\n<p>The command and associated output is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4212.hsg-11-26-12-02.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4212.hsg-11-26-12-02.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<h2>Using Get-CimClass to find WMI methods<\/h2>\n<p>In the same way that I can find writable WMI properties, I can also find <em>implemented <\/em>WMI methods. A WMI class may have five methods and only three of them might have the <strong>implemented<\/strong> qualifier. This is because all WMI classes inherit from other WMI classes that inherit from other WMI classes (and so on and so on). Therefore, an abstract may have a <strong>SetPowerState<\/strong><em> <\/em>method, but the dynamic WMI class I want to use may not implement the method (indeed, I know of no WMI class that implements the <strong>SetPowerState<\/strong> method).<\/p>\n<p>So, in the same way I looked for the <strong>write<\/strong> qualifier for cimclassproperties, I look for the <strong>implemented<\/strong> qualifier for the cimclassmethods property, as shown here.<\/p>\n<p style=\"padding-left: 30px\">Get-CimClass win32_computersystem | select -ExpandProperty cimclassmethods |<\/p>\n<p style=\"padding-left: 30px\">where qualifiers -match &#8216;implemented&#8217; | Format-Table name, qualifiers<\/p>\n<p>The code to look at the implemented methods of the Win32_ComputerSystem WMI class (along with the associated results) is shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3225.hsg-11-26-12-03.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3225.hsg-11-26-12-03.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Well, the Scripting Wife just came back to our seats with tea and chocolate (I did not ask her to find a snack, she just did it because she is nice). I guess I need to put the laptop up for a bit. Join me tomorrow when I will talk about using Windows PowerShell and WMI to view or to set power plans. It&rsquo;s cool.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">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\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/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: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell&nbsp;3.0 and the CIM cmdlets to explore WMI classes. Microsoft Scripting Guy, Ed Wilson, is here. Today, the Scripting Wife and I are on the train from Dortmund to Geneva. Teresa was really smart and found tickets for us to tour the Particle Accelerator at [&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":[1],"tags":[362,3,367,45],"class_list":["post-4592","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-powershell-3","tag-scripting-guy","tag-windows-8","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell&nbsp;3.0 and the CIM cmdlets to explore WMI classes. Microsoft Scripting Guy, Ed Wilson, is here. Today, the Scripting Wife and I are on the train from Dortmund to Geneva. Teresa was really smart and found tickets for us to tour the Particle Accelerator at [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4592","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=4592"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4592\/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=4592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=4592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=4592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}