{"id":2221,"date":"2012-08-24T15:42:26","date_gmt":"2012-08-24T15:42:26","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2012\/08\/24\/introduction-to-cim-cmdlets\/"},"modified":"2021-03-04T20:55:29","modified_gmt":"2021-03-05T04:55:29","slug":"introduction-to-cim-cmdlets","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/introduction-to-cim-cmdlets\/","title":{"rendered":"Introduction to CIM Cmdlets"},"content":{"rendered":"<p>PowerShell 3.0 shipping with Windows server 2012 and Windows 8 brings a new set of Cmdlets to manage any server or device that complies with CIM and WS-Man standards defined by DMTF. In this blog post we will explore these new Cmdlets and how can they help IT Pros in managing a datacenter.<\/p>\n<p>The list of new Cmdlets is given in the table below:<\/p>\n<table border=\"1\" width=\"668\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"205\"><b>Cmdlet<\/b><\/td>\n<td valign=\"top\" width=\"461\"><b>Purpose<\/b><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"205\">Get-CimInstance<\/td>\n<td valign=\"top\" width=\"461\">Gets instances of a class.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"205\">New-CimInstance<\/td>\n<td valign=\"top\" width=\"461\">Creates a new instance of a class.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"205\">Remove-CimInstance<\/td>\n<td valign=\"top\" width=\"461\">Removes one of more instances of a class.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"205\">Set-CimInstance<\/td>\n<td valign=\"top\" width=\"461\">Modifies one or more instances of a class.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"205\">Get-CimAssociatedInstance<\/td>\n<td valign=\"top\" width=\"461\">Gets all the associated instances for a particular instance.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"205\">Invoke-CimMethod<\/td>\n<td valign=\"top\" width=\"461\">Invokes instance or static method of a class.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"205\">Get-CimClass<\/td>\n<td valign=\"top\" width=\"461\">Gets class schema of a CIM class.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"205\">Register-CimIndicationEvent<\/td>\n<td valign=\"top\" width=\"461\">Helps subscribe to events.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"205\">New-CimSession<\/td>\n<td valign=\"top\" width=\"461\">Creates a CIM Session with local or a remote machine<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"205\">Get-CimSession<\/td>\n<td valign=\"top\" width=\"461\">Gets a list of CIM Sessions that have been made.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"205\">Remove-CimSession<\/td>\n<td valign=\"top\" width=\"461\">Removes CimSessions that are there on a machine.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"205\">New-CimSessionOption<\/td>\n<td valign=\"top\" width=\"461\">Creates a set of options that can be used while creating a CIM session.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h3>Basic terminology<\/h3>\n<p>If you are already familiar with terms like WMI, CIM, WinRM and WS-Man, you can skip this section.<\/p>\n<p><b>CIM<\/b>: Common Information Model (CIM) is the DMTF standard [DSP0004] for describing the structure and behavior of managed resources such as storage, network, or software components.<\/p>\n<p><b>WMI<\/b>: Windows Management Instrumentation (WMI) is a CIM server that implements the CIM standard on Windows.<\/p>\n<p><b>WS-Man<\/b>: WS-Management (WS-Man) protocol is a SOAP-based, firewall-friendly protocol for management clients to communicate with CIM servers.<\/p>\n<p><b>WinRM:<\/b> Windows Remote Management (WinRM) is the Microsoft implementation of the WS-Man protocol on Windows.<\/p>\n<p>&nbsp;<\/p>\n<h3>Why new Cmdlets<\/h3>\n<p>With Windows Server 2012, Windows has shifted its focus to become a Cloud OS. In a datacenter running a private or public cloud \u2013 there are always set of devices and servers from different vendors. We strongly believe that the only way to reduce the cost of running datacenters is through automation built on top of standards. There is less learning and less chances of error when IT Pros are able to automate heterogeneous environment using same set of tools that they have learned for Windows.<\/p>\n<p>This was not the case with previous versions of PowerShell. We had two set of Cmdlets to manage Windows and Non-Windows. WMI Cmdlets were primarily used to manage Windows and WsMan Cmdlets were targeted at non-Windows that implemented WsMan standard.<\/p>\n<p><b>WMI Cmdlets: <\/b><\/p>\n<blockquote><p>&#8211; Pros: Provided better task abstraction compared to WsMan Cmdlets, output is a .NET object.<\/p><\/blockquote>\n<blockquote><p>&#8211; Cons: Use of non-standard DCOM protocol. Does not work for non-Windows. <b><\/b><\/p><\/blockquote>\n<p><b>WinRM Cmdlets<\/b><\/p>\n<blockquote><p>&#8211; Pros: Works with Windows and non-Windows using standard protocol.<\/p><\/blockquote>\n<blockquote><p>&#8211; Cons: Poor task abstraction. Output is XML , scaring most IT Pros away<\/p><\/blockquote>\n<p>We heard from you that the major obstacle in PS scripting for WMI is lack of discoverability. We also heard that WMI Cmdlets don\u2019t provide first class PS experience. There are issues with serializing a WMI object, there is no concept of session reuse and WMI object has weird looking property names (like __Server). Last but not least, there is poor formatting for most of the commonly used WMI classes. Someone said \u201cWhen I run Get-WmiObject Win32_process, I feel like standing on bridge above freeway and lot of traffic zipping in front of my eyes\u201d.<\/p>\n<h3>Key goals for new CIM Cmdlets<\/h3>\n<blockquote><p>&#8211; <strong>Rich PowerShell experience<\/strong>. Make CIM a first class citizen of PS, addressing usability concerns and user feedback for WMI and WsMan Cmdlets.<\/p><\/blockquote>\n<blockquote><p>&#8211; <strong>Standard compliance<\/strong>. With so much focus on standards, our goal is to make PowerShell the best platform for managing Windows and Non-Windows. New CIM Cmdlets should be able to manage any CIM + WsMan compliant endpoint, including Windows.<\/p><\/blockquote>\n<blockquote><p>&#8211; <strong>Support for down-level machines<\/strong>. We understand that there are more down-level servers in a datacenter than there would be Windows Server 2012 for some time to come. We want to make sure same set of Cmdlets can be used to manage down-level Windows as well.<\/p><\/blockquote>\n<p>In the subsequent sections we will talk about each of these goals in detail.<\/p>\n<p>&nbsp;<\/p>\n<h3><u>Goal 1 &#8211; Rich PowerShell experience<\/u><\/h3>\n<h4><strong>1. Discovery of classes and namespaces.<\/strong><\/h4>\n<p>There is a famous joke about WMI, often attributed to Jeffrey Snover. \u201cIT Pros love and hate WMI. They love it because there is so much they accomplish with WMI and PowerShell. They hate it because it is very difficult to discover what\u2019s in there\u201d<\/p>\n<p>To address this, we have done key improvements in new CIM Cmdlets<\/p>\n<ol>\n<li>Tab completion for classname and namespace parameters.<\/li>\n<li>Get-CimClass Cmdlet<\/li>\n<\/ol>\n<table style=\"color: #ffffff;\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#000066\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"638\"><span style=\"color: #808080;\"># Using tab completion for CIM cmdlet parameters ( Tab+Space in ISE shows a drop down)<\/span><\/p>\n<p><span style=\"color: #808080;\">Get-CimInstance \u2013Namespace &lt;Tab&gt; #Finding top-level namespaces<\/span><\/p>\n<p><span style=\"color: #808080;\"># Tab completion for class names<\/span><\/p>\n<p><span style=\"color: #808080;\"># If namespace is not specified, shows classes from default root\/cimv2 namespace<\/span><\/p>\n<p><span style=\"color: #808080;\">Get-CimInstance -ClassName *Bios&lt;Tab&gt;<\/span><\/p>\n<p><span style=\"color: #808080;\">Get-CimInstance \u2013Namespace root\/Microsoft\/Windows\/smb \u2013ClassName &lt;tab&gt;<\/span><\/p>\n<p><span style=\"color: #808080;\"># Note: Tab completion only works for local machine.<\/span><\/p>\n<p><span style=\"color: #808080;\">#Using Get-CimClass for advanced class search<\/span><\/p>\n<p><span style=\"color: #808080;\">#All classes in root\/cimv2<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt;Get-CimClass<\/span><\/p>\n<p><span style=\"color: #808080;\">#Classes named like disk<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt;Get-CimClass -ClassName *disk*<\/span><\/p>\n<p><span style=\"color: #808080;\"># The Cmdlet makes querying much easier (what would require scripting before)<\/span><\/p>\n<p><span style=\"color: #808080;\"># Get all classes starting with &#8220;Win32&#8221; that have method starting with &#8220;Term&#8221;<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt;Get-CimClass Win32* -MethodName Term*<\/span><\/p>\n<p><span style=\"color: #808080;\"># Get classes starting with &#8220;Win32&#8221; that have a property named &#8220;Handle&#8221;<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt;Get-CimClass Win32* -PropertyName Handle<\/span><\/p>\n<p><span style=\"color: #808080;\"># Get classes starting with &#8220;Win32&#8221; that have the &#8220;Association&#8221; qualifier<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt;Get-CimClass Win32* -QualifierName Association<\/span><\/p>\n<p><span style=\"color: #808080;\">#Find classes used for events<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-CimClass -Namespace root\/Microsoft\/Windows\/smb -class *Smb* -QualifierName Indication<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Get-CimClass and tab completion described above only works for local machine. If you specify ComputerName or CimSession parameter, tab completion would not work. In order to make tab completion more efficient, PowerShell caches the list of namespaces and classnames.<\/p>\n<h4><strong>2. Getting Instances<\/strong><\/h4>\n<p>Getting\/Enumerating instance of a class is the most commonly performed operation. We wanted the new Get-CimInstance Cmdlet to have better performance and even better user experience as compared to the old Get-WmiObject cmdlet. To achieve these goals we made the following design decisions:<\/p>\n<p>a. The Get-CimInstance cmdlet returns one or more instances of CimInstance. CimInstance is different from the object returned by Get-WmiObject.<\/p>\n<p>b. __Properties are no longer mixed with properties of an instance.<\/p>\n<p>c. Reduce memory and on-the-wire footprint by allowing retrieval of a subset of properties.<\/p>\n<p>d. Allow retrieval of key properties.<\/p>\n<p>e. Allow creation of in-memory instance to reduce round trips.<\/p>\n<p>f. Allow retrieval of specific instances using in-memory instances or actual instances.<\/p>\n<p>g. DateTime values are returned as objects of System.DateTime type. Old cmdlets treat them as strings.<\/p>\n<p>&nbsp;<\/p>\n<table style=\"color: #ffffff;\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#000066\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"638\"><span style=\"color: #808080;\"># Get-CimInstance was designed to be similar to the Get-WmiObject<\/span><\/p>\n<p><span style=\"color: #808080;\"># WMI Cmdlet : Get-WmiObject -class Win32_Process<\/span><\/p>\n<p><span style=\"color: #808080;\"># WsMan Cmdlet : get-wsmaninstance wmicimv2\/win32_process -Enumerate<\/span><\/p>\n<p><span style=\"color: #808080;\"># The default value of -Namespace is root\/cimv2, and the default value of -ComputerName is local computer<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-CimInstance -Class Win32_Process<\/span><\/p>\n<p><span style=\"color: #808080;\"># Filtering using WQL<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-CimInstance -Query &#8220;SELECT * FROM Win32_Process WHERE Name Like &#8216;power%'&#8221;<\/span><\/p>\n<p><span style=\"color: #808080;\"># use the -Filter parameter with -classname<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-CimInstance -Class Win32_Process -Filter &#8220;Name Like &#8216;power%'&#8221;<\/span><\/p>\n<p><span style=\"color: #808080;\">#Retrieving a subset of properties : To reduce memory and on-the-wire footprint<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-CimInstance -Class Win32_Process -Property Name, Handle<\/span><\/p>\n<p><span style=\"color: #808080;\">#Only get the key properties<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-CimInstance -Class Win32_Process -KeyOnly<\/span><\/p>\n<p><span style=\"color: #808080;\">########################## Looking into CimInstance #########################<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt;\u00a0 $x, $y = Get-CimInstance Win32_Process<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt;\u00a0 $x | gm<\/span><\/p>\n<p><span style=\"color: #808080;\"># The object contains the full CIM class derivation hierarchy<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $x.pstypenames<\/span><\/p>\n<p><span style=\"color: #808080;\"># The object also has a reference to its class declaration<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $x.CimClass | gm<\/span><\/p>\n<p><span style=\"color: #808080;\"># DateTime values are returned as strings<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-WmiObject Win32_OperatingSystem | Select *Time*<\/span><\/p>\n<p><span style=\"color: #808080;\"># DateTime values are returned as System.DateTime<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-CimInstance Win32_OperatingSystem | Select *Time*#<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4><strong>3. Working with associations<\/strong><\/h4>\n<p>Working with associations was not straight forward in the old WMI cmdlets. Customers wanted a way to find out associated instances of a particular instance. To resolve this issue we came up with a cmdlet called Get-CimAssociatedInstance. The following example shows some of the important features of this cmdlet.<\/p>\n<table style=\"color: #ffffff;\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#000066\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"638\"><span style=\"color: #808080;\"># Get instance of Win32_LogicalDisk class with DriveType =3 (hard drives)<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $disk1, $diskn = Get-CimInstance -class Win32_LogicalDisk -Filter &#8216;DriveType = 3&#8217;<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $disk1<\/span><\/p>\n<p><span style=\"color: #808080;\"># Get the all instances associated with this disk<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-CimAssociatedInstance -CimInstance $disk1<\/span><\/p>\n<p><span style=\"color: #808080;\"># Get instances of a specific type<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-CimAssociatedInstance -CimInstance $disk1 -ResultClassName Win32_DiskPartition<\/span><\/p>\n<p><span style=\"color: #808080;\"># Finding associated instances through a specific CIM relationship<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-CimAssociatedInstance -CimInstance $diskn -Association Win32_LogicalDiskRootDirectory<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4><strong>4. Working with methods<\/strong><\/h4>\n<p>A large number of tasks in WMI are achieved by invoking methods. The new Invoke-CimMethod makes two things really easy:<\/p>\n<blockquote><p>a. Discovery of method and method parameters<\/p><\/blockquote>\n<blockquote><p>b. Execution of methods with parameters. Using feedback from our customers: <a href=\"https:\/\/connect.microsoft.com\/PowerShell\/feedback\/details\/624263\/invoking-wmi-methods-with-invoke-wmimethod\">Connect bug<\/a><\/p><\/blockquote>\n<p>The following examples show how easy it is to discover and execute methods using Invoke-CimMethod:<\/p>\n<table style=\"color: #ffffff;\" border=\"1\" width=\"725\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#000066\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"723\"><span style=\"color: #808080;\">PS:&gt; $class = Get-CimClass Win32_Process<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $class.CimClassMethods<\/span><\/p>\n<p><span style=\"color: #808080;\"># Get the parameters of the Create method<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $class.CimClassMethods[&#8220;Create&#8221;].Parameters<\/span><\/p>\n<p><span style=\"color: #808080;\"># Invoke the static Create method on the Win32_Process class to create an instance of the Notepad<\/span><\/p>\n<p><span style=\"color: #808080;\"># application. Notice that the method parameters are given in a hash table since CIM method arguments<\/span><\/p>\n<p><span style=\"color: #808080;\"># are unordered by definition.<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Invoke-CimMethod -Class win32_process -MethodName Create -Argument @{CommandLine=&#8217;notepad.exe&#8217;;<\/span><\/p>\n<p><span style=\"color: #808080;\">CurrentDirectory = &#8220;c:\\windows\\system32&#8221;}<\/span><\/p>\n<p><span style=\"color: #808080;\"># Get the owners of the running Notepad instances<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $result = Invoke-CimMethod -Query &#8216;SELECT * FROM Win32_Process WHERE name like &#8220;notepad%&#8221;&#8216;<\/span><\/p>\n<p><span style=\"color: #808080;\">-MethodName GetOwner<\/span><\/p>\n<p><span style=\"color: #808080;\"># The result has the returned value and out parameters of the method<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $result<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4><strong>5. CliXML serialization.<\/strong><\/h4>\n<p>CimInstance supports full fidelity serialization and deserialization. This is an important feature for those who wish to save state of an instance or result of a cmdlet and then want to use it later. The WMI cmdlets do not support full-fidelity serialization\/deserialization.<\/p>\n<table style=\"color: #ffffff;\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#000066\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"638\"><span style=\"color: #808080;\"># CimInstances are serialized and deserialized with full fidelity<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $x = Get-CimInstance Win32_Service<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $x<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $x[0].pstypenames<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $x | Export-CliXml t1.xml<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $y = Import-CliXml .\\t1.xml<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $y<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $y[0].pstypenames<\/span><\/p>\n<p><span style=\"color: #808080;\"># The deserialized objects are identical to the ones obtained from the server<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; diff ($y) (Get-CimInstance win32_service )<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4><strong>6. Remote management<\/strong><\/h4>\n<p>Managing remote machines with the new cmdlets is also pretty simple and straight forward. The two parameters that can be used to manage remote machines are:<\/p>\n<blockquote><p>a. ComputerName<\/p><\/blockquote>\n<blockquote><p>b. CimSession<\/p><\/blockquote>\n<p>The following example will explain how these two parameters can be used to manage a remote machine.<\/p>\n<table style=\"color: #ffffff;\" border=\"1\" width=\"729\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#000066\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"727\"><span style=\"color: #808080;\">PS:&gt; $props = @{v_Key = [UInt64] 8;}<\/span><\/p>\n<p><span style=\"color: #808080;\"># If ComputerName parameter is used, the cmdlets create an implicit session during the execution.<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $inst = New-CimInstance -ClassName TestClass -Namespace root\\test -Key v_Key -Property $props<\/span><\/p>\n<p><span style=\"color: #808080;\">-ComputerName SecondWin8Server<\/span><\/p>\n<p><span style=\"color: #808080;\"># Create a session<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $session = New-CimSession \u2013ComputerName SecondWin8Server<\/span><\/p>\n<p><span style=\"color: #808080;\"># Use the session<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $inst = New-CimInstance -ClassName TestClass -Namespace root\\test -Key v_Key -Property $props<\/span><\/p>\n<p><span style=\"color: #808080;\">\u2013CimSession $session<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Tip:<\/strong> If a large number of remote operations are to be performed then session reuse is highly recommended. This can provide a significant performance gain.<\/p>\n<h4><strong>7. Easy migration from WMI cmdlets<\/strong><\/h4>\n<p>Last, but not the least, a very important aspect is to reduce learning. If you know how to use WMI cmdlets from PowerShell 2.0, you will find learning new CIM cmdlets easy. These cmdlets follow similar patterns as WMI cmdlets -including parameter names and alias. Let\u2019s see how easy or difficult it is to move to new cmdlets<\/p>\n<table style=\"color: #ffffff;\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#000066\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"638\"><span style=\"color: #808080;\"><b># OLD: One liner to get ComputerSystem information<\/b><\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-WmiObject Win32_ComputerSystem<\/span><\/p>\n<p><span style=\"color: #808080;\"><b># NEW:<\/b><\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-CimInstance Win32_ComputerSystem<\/span><\/p>\n<p><span style=\"color: #808080;\"># ClassName is position and mandatory.<\/span><\/p>\n<p><span style=\"color: #808080;\"># Namespace default is root\/cimv2 namespace<\/span><\/p>\n<p><span style=\"color: #808080;\">#WMI Cmdlet \u2013 with classnames and Namespace<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-WmiObject \u2013ClassName Win32_Process \u2013Namespace root\/cimv2<\/span><\/p>\n<p><span style=\"color: #808080;\">#CIM cmdlet follows the same pattern<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-CimInstance \u2013ClassName Win32_Process \u2013Namespace root\/cimv2<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The table below shows the list of WMI cmdlets and their CIM equivalent:<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"319\"><b>Old cmdlet<\/b><\/td>\n<td valign=\"top\" width=\"319\"><b>New Cmdlet<\/b><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"319\">Get-WmiObject<\/td>\n<td valign=\"top\" width=\"319\">Get-CimInstance<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"319\">Get-WmiObject -list<\/td>\n<td valign=\"top\" width=\"319\">Get-CimClass<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"319\">Set-WmiInstance<\/td>\n<td valign=\"top\" width=\"319\">Set-CimInstance<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"319\">Set-WmiInstance \u2013PutType CreateOnly<\/td>\n<td valign=\"top\" width=\"319\">New-CimInstance<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"319\">Remove-WmiObject<\/td>\n<td valign=\"top\" width=\"319\">Remove-CimInstance<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"319\">Invoke-WmiMethod<\/td>\n<td valign=\"top\" width=\"319\">Invoke-CimMethod<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>Note: <\/b>In old cmdlets Set-WmiInstance was used to perform update and create operations. The new cmdlets clearly define the distinction between the two operations i.e. New-CimInstance is used to create an instance and Set-CimInstance is used to update an existing instance.<\/p>\n<p>You will also notice that in some places we have broken this rule \u2013 and script using WMI cmdlet can\u2019t be simply changed to CIM cmdlet by changing the cmdlet name. e.g.<\/p>\n<table style=\"color: #ffffff;\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#000066\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"638\"><span style=\"color: #808080;\"><b># OLD:<\/b><\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Invoke-WMIMethod -class Win32_Process -Name create -ArgumentList &#8216;calc.exe&#8217;<\/span><\/p>\n<p><span style=\"color: #808080;\"><b># NEW:<\/b><\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt;Invoke-CimMethod Win32_Process -MethodName create -Arguments @{CommandLine=&#8217;calc.exe&#8217;}<\/span><\/p>\n<p><span style=\"color: #808080;\">New Cmdlet takes a hash table or ordered dictionary as input not an Object.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The rule here is, if the WMI cmdlet experience is not ideal, we don\u2019t want to carry it forward. It\u2019s better to break a bad experience (like in the example given above)<\/p>\n<p>&nbsp;<\/p>\n<h3><u>Goal 2 &#8211; Standard Compliance<\/u><\/h3>\n<p>\u00b7 CIM cmdlets are modeled on generic CIM operations<\/p>\n<p>\u00b7 Work over WsMan for remote management, making it possible to manage any server or device that implements WsMan and CIM standard.<\/p>\n<p>\u00b7 Removes the need to build custom agents and\/or protocol to manage complex heterogeneous environments<\/p>\n<p>\u00b7 CIM cmdlets will work seamlessly with the new Open Management Infrastructure. <a href=\"http:\/\/blogs.technet.com\/b\/windowsserver\/archive\/2012\/06\/28\/open-management-infrastructure.aspx\">http:\/\/blogs.technet.com\/b\/windowsserver\/archive\/2012\/06\/28\/open-management-infrastructure.aspx<\/a><\/p>\n<p>The following example shows that CimCmdlets can be used to manage a non-windows device (i.e. an Intel AMT box):<\/p>\n<table style=\"color: #ffffff;\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#000066\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"638\"><span style=\"color: #808080;\"># Save credentials in an object<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $cred = Get-Credential -UserName admin<\/span><\/p>\n<p><span style=\"color: #808080;\"># Create a session with Intel AMT machine.<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $s = New-CimSession -ComputerName $serverAMT -Port 16992 -Authentication Digest -Credential $cred<\/span><\/p>\n<p><span style=\"color: #808080;\"># Use classname to get instances from an Intel AMT machine.<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-CimInstance -class CIM_ComputerSystem -Namespace interop -CimSession $s<\/span><\/p>\n<p><span style=\"color: #808080;\"># Use resourceURI to get instances from an Intel AMT machine.<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $resourceURI = \u201chttp:\/\/intel.com\/wbem\/wscim\/1\/amt-schema\/1\/AMT_GeneralSettings\u201d<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; Get-CimInstance -ResourceUri $resourceURI -Namespace interop -CimSession $s<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><\/h3>\n<h3><\/h3>\n<h3><u>Goal 3 &#8211; Support for down-level OS or non-windows machines<\/u><\/h3>\n<p>CimCmdlets can be used to manage Windows 8, down-level windows machines and any machine that has a CIM standards compliant CIMOM. So, IT pros can now manage non-windows machines with PowerShell in the exact same fashion as they could manage a windows box.<\/p>\n<p>To manage these machines, a CimSession to the machine is required. Once a CimSession is created, the machine can be managed irrespective of the operating system.<\/p>\n<p>WinRM support on down-level windows machines is limited. The latest WMF-V1 release will enable the latest version of WinRM on the down-level machines; this will help our customers in making best use of these new cmdlets.<\/p>\n<p>If customers do not want to install WMF-V1 or do not wish to use WinRM then they can always use DCOM protocol to achieve the same results.<\/p>\n<p>&nbsp;<\/p>\n<table style=\"color: #ffffff;\" border=\"1\" width=\"824\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#000066\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"822\"><span style=\"color: #808080;\"># If ComputerName is specified, WinRM protocol is used<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $serverwin8 = New-CimSession \u2013ComputerName &#8220;ServerWin8&#8221;<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $serverwin2k8r2 = New-CimSession \u2013ComputerName \u201cServerwin2k8r2 &#8220;<\/span><\/p>\n<p><span style=\"color: #808080;\"># For a remote machine, if you wish to go over DCOM, you need to explicitly specify<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $sOpt = New-CimSessionOption \u2013Protocol DCOM<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $sessionWin2k8r2Dcom = New-CimSession \u2013ComputerName \u201cServerwin2k8r2 &#8221; \u2013SessionOption $sOpt<\/span><\/p>\n<p><span style=\"color: #808080;\"># User Experience remains same irrespective of the target machine.<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $instanceServerWin8 = Get-CimInstance \u2013CimSession $ serverwin8<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $instanceServerWin2k8r2 = Get-CimInstance \u2013CimSession $ serverwin2k8r2<\/span><\/p>\n<p><span style=\"color: #808080;\">PS:&gt; $instanceServerWin2k8r2DCOM = Get-CimInstance \u2013CimSession $ sessionWin2k8r2Dcom<\/span><\/p>\n<p><span style=\"color: #808080;\">#Note: The results in $instanceServerWin2k8r2 and $instanceServerWin2k8r2DCOM are identical in all aspects.<\/span><\/p>\n<p><span style=\"color: #808080;\"># Only the protocol used to get them is different.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Our objective is to provide the best user experience to all the IT professionals. We would love to know what you think about these new cmdlets. Please give us your comments below.<\/p>\n<p>&nbsp;<\/p>\n<p>Vaibhav Chugh<\/p>\n<p>SDET, WMI<\/p>\n<p>Osama Sajid<\/p>\n<p>Program Manager, WMI<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PowerShell 3.0 shipping with Windows server 2012 and Windows 8 brings a new set of Cmdlets to manage any server or device that complies with CIM and WS-Man standards defined by DMTF. In this blog post we will explore these new Cmdlets and how can they help IT Pros in managing a datacenter. The list [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[112,115,214,26],"class_list":["post-2221","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-cim","tag-ciminstance","tag-mi-client","tag-wmi"],"acf":[],"blog_post_summary":"<p>PowerShell 3.0 shipping with Windows server 2012 and Windows 8 brings a new set of Cmdlets to manage any server or device that complies with CIM and WS-Man standards defined by DMTF. In this blog post we will explore these new Cmdlets and how can they help IT Pros in managing a datacenter. The list [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/2221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=2221"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/2221\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=2221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=2221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=2221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}