{"id":6691,"date":"2015-04-13T00:01:00","date_gmt":"2015-04-13T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2015\/04\/13\/working-with-volumes-in-cim\/"},"modified":"2019-02-18T10:29:55","modified_gmt":"2019-02-18T17:29:55","slug":"working-with-volumes-in-cim","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/working-with-volumes-in-cim\/","title":{"rendered":"Working with Volumes in CIM"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Microsoft Scripting Guy, Ed Wilson, talks about working with volumes with Windows PowerShell and CIM.<\/span>\n<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;Hey, Scripting Guy! I don&rsquo;t understand CIM at all. I mean, I thought it was basically WMI, but when I use WMI to look at volumes, I see different stuff. Can you help me?\n&mdash;AB\n<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\">&nbsp;Hello AB,\nMicrosoft Scripting Guy, Ed Wilson, is here. There are some questions that seem to be rather easy to answer, and then become confusing. So I am going to jump in and introduce CIM Week.\nThe Windows Management Instrumentation (WMI) is Microsoft&rsquo;s implementation of the Common Information Model (CIM). WMI has been around since NT&nbsp;4.0. Although it does a great job, there are some issues with it.\nFor one thing, is relies on Distributed COM (DCOM) and Remote Procedure Calls (RPC)&mdash;both of which involve a bit of overhead. In addition, it is not very firewall friendly because it requires a large number of open ports.\nIn Windows 8, we introduced something that would be lighter, that would be firewall friendly, and that would work with the remoting features in Windows PowerShell. It becomes a bit confusing that we call the cmdlets &#8220;CIM cmdlets.&#8221; Technically, WMI stuff also could be called CIM stuff because it implements CIM. The Windows PowerShell team blog has some great articles that explore the architecture and implantation details, and take a specific example to look at why things seem different.\nThere is a <b>Get-Volume<\/b> command. I say command because <b>Get-Command<\/b> lists it as a function from the Storage module. These are wrappers.\nWhere some of the confusion comes into play, is in comparing it to the Win32_Volume WMI class. The output is similar, but different.\nWhen I use <b>Get-Volume<\/b> on my local machine, it returns a nicely formatted output. This is shown here:<\/p>\n<p style=\"margin-left:30px\">PS C:&gt; Get-Volume<\/p>\n<p style=\"margin-left:30px\">DriveLetter FileSystemLabel FileSystem&nbsp; DriveType&nbsp; HealthStatus SizeRemaining Size<span style=\"font-size:12px\">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<\/span><\/p>\n<p style=\"margin-left:30px\">&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;-&nbsp; &#8212;&#8212;&#8212;&nbsp; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;-<\/p>\n<p style=\"margin-left:30px\">C &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NTFS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Fixed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Healthy&nbsp;&nbsp;&nbsp;&nbsp; 108.53 GB&nbsp; 126.48 GB<\/p>\n<p style=\"margin-left:30px\">E&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NEW VOLUME&nbsp; FAT32&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fixed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Healthy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.52 GB&nbsp;&nbsp;&nbsp; 1.99 GB<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Recovery&nbsp;&nbsp;&nbsp; NTFS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fixed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Healthy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 59.83 MB&nbsp;&nbsp;&nbsp;&nbsp; 300 MB<\/p>\n<p style=\"margin-left:30px\">D&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CD-ROM&nbsp;&nbsp;&nbsp;&nbsp; Healthy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 B\nOne of the things that is a bit confusing with <b>Get-Volume<\/b> is that there is no <b>&ndash;ComputerName<\/b> parameter. It might seem to be a huge oversight. But there is a parameter named <b>&ndash;CimSession<\/b>. OK, fine. But does that mean I need to first create a CIM session to use the command? And if so, how do I do that?\nOne thing that is great about the CIM commands is that I can create a CIM session to multiple computers at the same time. I can then use that CIM session as an argument to the <b>&ndash;CimSession<\/b> parameter. Here is an example:<\/p>\n<p style=\"margin-left:30px\">PS C:&gt; $cim = New-CimSession dc1, sgw<\/p>\n<p style=\"margin-left:30px\">PS C:&gt; Get-Volume -CimSession $cim<\/p>\n<p style=\"margin-left:30px\">DriveLetter FileSystem FileSystem DriveType HealthStatus SizeRemaining Size PSComputerName<\/p>\n<p style=\"margin-left:30px\"><span style=\"font-size:12px\">&#8212;&#8212;&#8212; &#8212;&#8212;&#8212; &#8212;&#8212;&#8212; &#8212;&#8212;&#8212; &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;- &#8212;&#8212;&#8212;<\/span><\/p>\n<p style=\"margin-left:30px\">C&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NTFS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fixed&nbsp;&nbsp;&nbsp;&nbsp; Healthy&nbsp;&nbsp; 116.91 GB 126.48 GB dc1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Recovery&nbsp; NTFS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fixed&nbsp;&nbsp;&nbsp;&nbsp; Healthy&nbsp;&nbsp;&nbsp; 59.83 MB&nbsp;&nbsp;&nbsp; 300 MB dc1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">D&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CD-ROM&nbsp;&nbsp;&nbsp; Healthy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 B dc1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System&#8230; NTFS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fixed&nbsp;&nbsp;&nbsp;&nbsp; Healthy&nbsp;&nbsp;&nbsp; 89.18 MB&nbsp;&nbsp;&nbsp; 350 MB sgw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">C&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NTFS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fixed&nbsp;&nbsp;&nbsp;&nbsp; Healthy &nbsp;&nbsp;116.86 GB 126.66 GB sgw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Removable Healthy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 B sgw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">D&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VMGUEST&nbsp;&nbsp; CDFS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CD-ROM&nbsp;&nbsp;&nbsp; Healthy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 B&nbsp; 26.31 MB sgw &nbsp; &nbsp;&nbsp;\nI can use the <b>Get-CimSession<\/b> parameter to see if there are any open CIM sessions. This is shown here:<\/p>\n<p style=\"margin-left:30px\">PS C:&gt; Get-CimSession<\/p>\n<p style=\"margin-left:30px\">Id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 3<\/p>\n<p style=\"margin-left:30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : CimSession3<\/p>\n<p style=\"margin-left:30px\">InstanceId&nbsp;&nbsp; : 84597c7e-f348-4f77-a320-3e36aec67a04<\/p>\n<p style=\"margin-left:30px\">ComputerName : dc1<\/p>\n<p style=\"margin-left:30px\">Protocol&nbsp;&nbsp;&nbsp;&nbsp; : WSMAN<\/p>\n<p style=\"margin-left:30px\">Id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 4<\/p>\n<p style=\"margin-left:30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : CimSession4<\/p>\n<p style=\"margin-left:30px\">InstanceId&nbsp;&nbsp; : 15cc6611-2085-4c1d-8e71-56c0f64dd08b<\/p>\n<p style=\"margin-left:30px\">ComputerName : sgw<\/p>\n<p style=\"margin-left:30px\">Protocol&nbsp;&nbsp;&nbsp;&nbsp; : WSMAN\n<span style=\"font-size:12px\">Note that the CIM sessions use WSMan. This is the standard Windows PowerShell remoting protocol that was introduced in Windows PowerShell&nbsp;2.0. It is cool because it uses a single port and is firewall friendly. In addition, introduced in Windows Server 2012, it is automatically enabled on server operating systems.<\/span>\nAs shown here, if I want to remove the CIM sessions, I use the <b>Remove-CimSession<\/b> cmdlet:<\/p>\n<p style=\"margin-left:30px\">PS C:&gt; Get-CimSession | Remove-CimSession<\/p>\n<p style=\"margin-left:30px\">PS C:&gt; Get-CimSession<\/p>\n<p style=\"margin-left:30px\">PS C:&gt;&nbsp;\nBut, I do not have to do that. I can supply a computer name as an argument to the <b>CimSession<\/b> parameter. When I do this, a connection is made, the command runs, and the connection drops. This is shown here:<\/p>\n<p style=\"margin-left:30px\">PS C:&gt; Get-Volume -CimSession dc1, sgw<\/p>\n<p style=\"margin-left:30px\">DriveLetter FileSystemLabel FileSystem DriveType HealthStatus SizeRemaining Size PSComputerName<\/p>\n<p style=\"margin-left:30px\"><span style=\"font-size:12px\">&#8212;&#8212;&#8212; &#8212;&#8212;&#8212; &#8212;&#8212;&#8212; &#8212;&#8212;&#8212; &#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;- &#8212;&#8212;&#8212;<\/span><\/p>\n<p style=\"margin-left:30px\">C&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NTFS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fixed&nbsp;&nbsp;&nbsp;&nbsp; Healthy&nbsp;&nbsp; 116.91 GB 126.48 GB dc1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Recovery&nbsp; NTFS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fixed&nbsp;&nbsp;&nbsp;&nbsp; Healthy&nbsp;&nbsp;&nbsp; 59.83 MB&nbsp;&nbsp;&nbsp; 300 MB dc1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">D&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CD-ROM&nbsp;&nbsp;&nbsp; Healthy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 B dc1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System&#8230; NTFS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fixed&nbsp;&nbsp;&nbsp;&nbsp; Healthy&nbsp;&nbsp;&nbsp; 89.18 MB&nbsp;&nbsp;&nbsp; 350 MB sgw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">C&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NTFS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fixed&nbsp;&nbsp;&nbsp;&nbsp; Healthy&nbsp;&nbsp; 116.86 GB 126.66 GB sgw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Removable Healthy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 B sgw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">D&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VMGUEST&nbsp;&nbsp; CDFS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CD-ROM&nbsp;&nbsp;&nbsp; Healthy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 B&nbsp; 26.31 MB sgw&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\nI can verify that nothing is left behind by again running <b>the Get-CimSession<\/b> cmdlet:<\/p>\n<p style=\"margin-left:30px\">PS C:&gt; Get-CimSession<\/p>\n<p style=\"margin-left:30px\">PS C:&gt;&nbsp;\nAB, that is all there is to using CIM to make a connection and to return volume information. CIM Week will continue tomorrow when I will talk about more cool Windows PowerShell stuff.\nI 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=\"http:\/\/blogs.technet.commailto: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.\n<b>Ed Wilson, Microsoft Scripting Guy<\/b><span style=\"font-size:12px\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about working with volumes with Windows PowerShell and CIM. &nbsp;Hey, Scripting Guy! I don&rsquo;t understand CIM at all. I mean, I thought it was basically WMI, but when I use WMI to look at volumes, I see different stuff. Can you help me? &mdash;AB &nbsp;Hello AB, Microsoft Scripting [&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,3,4,45],"class_list":["post-6691","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-cim","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about working with volumes with Windows PowerShell and CIM. &nbsp;Hey, Scripting Guy! I don&rsquo;t understand CIM at all. I mean, I thought it was basically WMI, but when I use WMI to look at volumes, I see different stuff. Can you help me? &mdash;AB &nbsp;Hello AB, Microsoft Scripting [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/6691","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=6691"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/6691\/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=6691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=6691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=6691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}