{"id":2113,"date":"2014-01-28T00:01:00","date_gmt":"2014-01-28T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/01\/28\/introduction-to-the-cimcmdlets-powershell-module\/"},"modified":"2022-06-20T14:54:44","modified_gmt":"2022-06-20T21:54:44","slug":"introduction-to-the-cimcmdlets-powershell-module","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/introduction-to-the-cimcmdlets-powershell-module\/","title":{"rendered":"Introduction to the CIMCmdlets PowerShell Module"},"content":{"rendered":"<p><strong>Summary<\/strong>: Guest blogger, Trevor Sullivan, talks about using the CIM module in Windows PowerShell.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Today we have a guest post from Trevor Sullivan. Trevor is an <a href=\"https:\/\/devblogs.microsoft.com\/scripting\/honorary-scripting-guys-announced\/\" target=\"_blank\" rel=\"noopener\">Honorary Scripting Guy<\/a>, and a recognized Microsoft Community Contributor (MCC). To see more of Trevor\u2019s guest posts, see these <a href=\"\/b\/heyscriptingguy\/archive\/tags\/windows+powershell\/guest+blogger\/trevor+sullivan\/\" target=\"_blank\" rel=\"noopener\">Hey, Scripting Guy! Blog posts<\/a>.\u00a0You can reach Trevor on Twitter\u00a0(<a href=\"https:\/\/twitter.com\/pcgeek86\" target=\"_blank\" rel=\"noopener\">https:\/\/twitter.com\/pcgeek86<\/a>) or\u00a0follow him on his blog,\u00a0<a href=\"http:\/\/trevorsullivan.net\/\" target=\"_blank\" rel=\"noopener\">Trevor Sullivan&#8217;s Tech Room, Minding the gap between administration and development<\/a>.<\/p>\n<p style=\"margin-left:30px\">\n  <b>Note\u00a0<\/b> This is the second in a series of five posts by Trevor where he will talk specifically about using the CIM cmdlets. Yesterday\u2019s post, <a href=\"https:\/\/devblogs.microsoft.com\/scripting\/what-is-cim-and-why-should-i-use-it-in-powershell\/\" target=\"_blank\" rel=\"noopener\">What is CIM and Why Should I Use It in PowerShell?<\/a>, provided a little bit of background on CIM and explained why you will want to use this exciting technology. Today\u2019s post talks about the CIMCmdlets Windows PowerShell module.\n<\/p>\n<p>Here\u2019s Trevor\u2026<\/p>\n<p>Windows PowerShell\u00a03.0, which was first included with Windows Server\u00a02012 and Windows\u00a08.0, introduced a new set of commands as part of a module called CIMCmdlets. The commands contained in the CIMCmdlets module offer several benefits over the legacy WMI cmdlets, including support for auto-completion and the use of the WS-Management remoting protocol.<\/p>\n<h2>Auto-completion<\/h2>\n<p>One of the more obvious usability enhancements in the CIMCmdlets module is the support for auto-completion of WMI namespace names and WMI class names. For example, if you were to use the <strong>Get-CimInstance<\/strong> cmdlet to retrieve instances of a WMI class, you can use tab-completion to fill in the values for the <strong>-Namespace<\/strong> and <strong>-ClassName<\/strong> parameters.<\/p>\n<p>If you attempt the same auto-completion operation by using the <strong>Get-WmiObject<\/strong> cmdlet, you will be sorely disappointed. The following image illustrates the way this has been incorporated into IntelliSense in the Windows PowerShell ISE.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-1-28-14-00.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/HSG-1-28-14-00.png\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<h2>Windows Remote Management<\/h2>\n<p>Under the hood, the CIMCmdlets module also offers something new that the WMI cmdlets cannot match. That capability is the use of the WS-Management remoting protocol (or WS-Man for short). WS-Management is implemented on the Windows platform through the Windows Remote Management (or WinRM) service. Every Microsoft Windows operating system since Windows\u00a07 has this WinRM service built-in, and all you need to do is enable it. Besides being standards-based, WinRM offers the awesome benefit of predictable network traffic via a single, static port.<\/p>\n<p>When you make outbound connections to the WinRM service, you no longer have to worry about the dynamic port allocation issue that plagued DCOM\/RPC. This simple fact will make dealing with security and network engineering personnel much easier, because they will not be required to open a large port range to accommodate DCOM\/RPC.<\/p>\n<p>DCOM\/RPC can be configured to use a static port since Windows NT\u00a04.0 (for more information, see <a href=\"http:\/\/support.microsoft.com\/kb\/154596\" target=\"_blank\" rel=\"noopener\">How to configure RPC dynamic port allocation to work with firewalls<\/a>). But it\u2019s not a standards-based remoting protocol, and trying to implement such customizations across your entire environment can be challenging, so it\u2019s probably just easier to use WinRM these days.<\/p>\n<h2>Limitations<\/h2>\n<p>The CIMCmdlets PowerShell module has several limitations compared the WMI cmdlets.<\/p>\n<p>First of all, most of the CIMCmdlets do not have a <strong>-Credential<\/strong> parameter. The only way to specify alternate credentials is to manually build a new CIM session object, and pass that into the <strong>-CimSession<\/strong> parameter on the other cmdlets. Due to this missing parameter, you are required to write additional code to provide alternate credentials. If you would like to see a <strong>-Credential<\/strong> parameter added in a future version of Windows PowerShell, please vote on this bug in Microsoft Connect: <a href=\"https:\/\/connect.microsoft.com\/PowerShell\/feedback\/details\/797120\/dcr-cimcmdlets-need-credential-parameter\" target=\"_blank\" rel=\"noopener\">DCR &#8211; CIMCmdlets need -Credential parameter<\/a>.<\/p>\n<p>The next major limitation of the CIMCmdlets is the absence of a number of useful WMI system properties. When you use <strong>Get-WmiObject<\/strong> to retrieve a WMI class definition, or an instance of a class, there are several properties that are automatically added. The names of these system properties all start with two underscores (for example: \u00a0__Derivation). Depending on your Windows PowerShell development goals, you may find this metadata to be useful. If you feel that this should be resolved in a future version of Windows PowerShell, please vote on this bug in Microsoft Connect: <a href=\"https:\/\/connect.microsoft.com\/PowerShell\/feedback\/details\/782064\/dcr-cim-cmdlets-not-returning-wmi-metadata\" target=\"_blank\" rel=\"noopener\">DCR &#8211; CIM cmdlets not returning WMI metadata<\/a>.<\/p>\n<p>The last major shortcoming of the CIMCmdlets (that I am aware of) is the lack of WMI methods on .NET objects. When <strong>Get-WmiObject<\/strong> was the new kid on the block, static or instance-level WMI methods would be dynamically bound to the .NET object. In CIMCmdlets, the objects retrieved from WMI are not \u201clive,\u201d so you cannot call methods on the .NET object directly. Instead, you must retrieve the CIM instance, and then pass it into the <strong>Invoke-CimMethod<\/strong> cmdlet. Unfortunately, this lack of functionality goes against one of the original <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/dd315275.aspx\" target=\"_blank\" rel=\"noopener\">Windows PowerShell design goals<\/a> of \u201cdiscoverability\u201d and being \u201cself-describing.\u201d<\/p>\n<p>That\u2019s all for today! In tomorrow\u2019s post, we will explore the commands in the CIMCmdlets module that you can use to retrieve and manipulate information.<\/p>\n<p>~Trevor<\/p>\n<p>Thank you, Trevor. CIM Week will continue tomorrow when we will have another guest blog post from Trevor.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\" rel=\"noopener\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\" rel=\"noopener\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\" rel=\"noopener\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\" rel=\"noopener\">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: Guest blogger, Trevor Sullivan, talks about using the CIM module in Windows PowerShell. Microsoft Scripting Guy, Ed Wilson, is here. Today we have a guest post from Trevor Sullivan. Trevor is an Honorary Scripting Guy, and a recognized Microsoft Community Contributor (MCC). To see more of Trevor\u2019s guest posts, see these Hey, Scripting Guy! [&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":[385,51,56,3,4,211,45,6],"class_list":["post-2113","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-cim","tag-getting-started","tag-guest-blogger","tag-scripting-guy","tag-scripting-techniques","tag-trevor-sullivan","tag-windows-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>Summary: Guest blogger, Trevor Sullivan, talks about using the CIM module in Windows PowerShell. Microsoft Scripting Guy, Ed Wilson, is here. Today we have a guest post from Trevor Sullivan. Trevor is an Honorary Scripting Guy, and a recognized Microsoft Community Contributor (MCC). To see more of Trevor\u2019s guest posts, see these Hey, Scripting Guy! [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2113","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=2113"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2113\/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=2113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=2113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=2113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}