{"id":4605,"date":"2012-11-25T00:01:00","date_gmt":"2012-11-25T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/11\/25\/weekend-scripter-the-easy-way-to-manage-disk-drives\/"},"modified":"2012-11-25T00:01:00","modified_gmt":"2012-11-25T00:01:00","slug":"weekend-scripter-the-easy-way-to-manage-disk-drives","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-the-easy-way-to-manage-disk-drives\/","title":{"rendered":"Weekend Scripter: The Easy Way to Manage Disk Drives"},"content":{"rendered":"<p><strong>Summary:<\/strong> Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell&nbsp;3.0 to manage disk drives on his Windows&nbsp;8 laptop.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Today, the Scripting Wife and I are back in Dortmund, Germany. We will spend the day with Windows PowerShell Guru Klaus Schulte. Our first day in Germany was spent in Dortmund where we had dinner at the Florian tower with Klaus, his lovely wife, Susanne, his daughter, Micah, and two sons, Janus and Marcos. The Florian tower is in the Westfalenpark, which has a great botanical garden, lots of jogging trails, and neat places for walking. The Florian tower is shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3005.HSG-11-25-12-1.jpg\"><img decoding=\"async\" title=\"Image of Florian tower\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3005.HSG-11-25-12-1.jpg\" alt=\"Image of Florian tower\" \/><\/a><\/p>\n<h2>Checking the status of disk drives by using Windows PowerShell<\/h2>\n<p>During our European trip, I am using an external disk drive I purchased to store all of the pictures I have been taking. My new camera stores both RAW and JPG picture formats, so each picture I take consumes nearly twice the space. My laptop drive is small, and therefore, I thought an external drive would be a perfect solution for the trip.<\/p>\n<p>The drive and my laptop both support USB 3.0, so speed works really well. However, there is one problem&mdash;external disks, such as the USB key fobs, appear removable to Windows. The big disk drive appears as a fixed disk, so I must go into Disk Manager to mount and dismount the drive. If I do not dismount the drive prior to shutting the laptop down, it searches forever on boot up, looking for the external drive that is missing. Using Disk Manager is a bit slow and involves the following steps.<\/p>\n<ol>\n<li>I have to go to the Start screen.<\/li>\n<li>Scroll over to <strong>Find<\/strong> and click the <strong>Administrative Tools<\/strong> tile.<\/li>\n<li>Locate and click <strong>Computer Management MMC<\/strong>.<\/li>\n<li>Find the <strong>Storage<\/strong> section, and then click <strong>Disk Management<\/strong>.<\/li>\n<li>After Disk Management appears, right-click the offline drive.<\/li>\n<li>Make it online.<\/li>\n<\/ol>\n<p>Of course, there is an easier way, just type <strong>diskmgmt<\/strong><em> <\/em>in the Windows PowerShell console, and the Disk Management MMC appears. Of course, one must remember that the MMC for Disk Management is <em>diskmgmt. <\/em><\/p>\n<p>Disk Management is shown here and shows my offline disk drive.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5126.hsg-11-25-12-02.png\"><img decoding=\"async\" title=\"Image of Computer Management\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5126.hsg-11-25-12-02.png\" alt=\"Image of Computer Management\" \/><\/a><\/p>\n<p>An easier way to check on the status of disk drives is to use the <strong>Get-Disk<\/strong> function (cmdlet) on Windows&nbsp;8 (and also on Windows Server&nbsp;2012). To do this, I only need to type <strong>Get-Disk<\/strong>, and a list of drives is displayed in the Windows PowerShell console. This is shown here (without my extra drive plugged in).<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Disk<\/p>\n<p style=\"padding-left: 30px\">Number Friendly Name &nbsp;Operational Status &nbsp;Total Size Partition Style<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;-&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; &#8212;&#8212;&#8212;&#8212;&nbsp; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8211;<\/p>\n<p style=\"padding-left: 30px\">0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INTEL SSDSA2BW160G3L &nbsp; &nbsp; &nbsp;Online &nbsp; &nbsp; &nbsp; 149.05 GB MBR<\/p>\n<p style=\"padding-left: 30px\"><strong>Note<\/strong> &nbsp;&nbsp;Using the <strong>Get-Disk<\/strong> function (cmdlet) requires Admin rights. If you run <strong>Get-Disk<\/strong> without Admin rights, the rather cryptic error message &ldquo;Access to a CIM resource was not available to the client&#8221; appears.<\/p>\n<p>When I add in my external USB disk drive and re-run the command, I see that the new drive is offline, as shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Disk<\/p>\n<p style=\"padding-left: 30px\">Number Friendly Name &nbsp;Operational Status &nbsp;Total Size Partition Style<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;-&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; &#8212;&#8212;&#8212;&#8212;&nbsp; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8211;<\/p>\n<p style=\"padding-left: 30px\">0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INTEL SSDSA2BW160G3L&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Online&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 149.05 GB MBR<\/p>\n<p style=\"padding-left: 30px\">1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SAMSUNG HN-M101MBB USB Device&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Offline&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 931.51 GB MBR&nbsp;<\/p>\n<h2>Bring on all offline disk drives<\/h2>\n<p>It is easy to bring online all offline disk drives. All I need to do is to use the <strong>Get-Disk<\/strong> function to retrieve all disk drive information, pipe the results to a <strong>Where-Object<\/strong> cmdlet to filter out for <em>isoffline<\/em> disk drives. I do this first to ensure I retrieved the intended disk drive, as shown here.<\/p>\n<p style=\"padding-left: 30px\"><strong>Note<\/strong>&nbsp;&nbsp; I have used the new Windows PowerShell <strong>Where<\/strong>&#8211;<strong>Object<\/strong> syntax, but this command only works on Windows&nbsp;8 and Windows Server&nbsp;2012, so it is not an issue. Oh, by the way, <strong>?<\/strong> is an alias for the <strong>Where-Object<\/strong> and has been since Windows PowerShell&nbsp;1.0.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Disk | ? isoffline<\/p>\n<p style=\"padding-left: 30px\">Number Friendly Name &nbsp;Operational Status &nbsp;Total Size Partition Style<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;-&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; &#8212;&#8212;&#8212;&#8212;&nbsp; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8211;<\/p>\n<p style=\"padding-left: 30px\">1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SAMSUNG HN-M101MBB USB Device&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Offline&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 931.51 GB MBR<\/p>\n<p>Perfect! Now I only need to retrieve the command, and then pipe the disk object to the <strong>Set-Disk<\/strong> function and specify that I want the value of the <strong>IsOffline<\/strong><em> <\/em>property to be <strong>False<\/strong> in order to bring the drive online, as shown here.<\/p>\n<p style=\"padding-left: 30px\">Get-Disk | ? IsOffline | Set-Disk -IsOffline:$false<\/p>\n<p>After I run the command, the new disk drive springs to life, and Windows Explorer opens to reveal the drive contents, so I know it worked. BUT, if I were not certain, I could always reuse the <strong>Get-Disk<\/strong> cmdlet, as shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Disk<\/p>\n<p style=\"padding-left: 30px\">Number Friendly Name &nbsp;Operational Status &nbsp;Total Size Partition Style<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;-&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; &#8212;&#8212;&#8212;&#8212;&nbsp; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8211;<\/p>\n<p style=\"padding-left: 30px\">0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INTEL SSDSA2BW160G3L&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Online&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 149.05 GB MBR<\/p>\n<p style=\"padding-left: 30px\">1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SAMSUNG HN-M101MBB USB Device&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Online&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 931.51 GB MBR<\/p>\n<p>OK. Everything looks groovy. But to be sure, I want to view all the information about my newly &ldquo;installed&rdquo; drive. So I pipe the results to the <strong>Format-List<\/strong> cmdlet (<strong>fl<\/strong> is an alias for this cmdlet). The command and the associated results appear in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5488.hsg-11-25-12-03.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5488.hsg-11-25-12-03.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<h2>Writing to read-only drives<\/h2>\n<p>For some reason, the first time I did this, the drive came online as read-only. When I attempted to dump my pictures from my camera, I obviously did not have a very good experience. I finally figured it out. One of the interesting things about the <strong>Set-Disk<\/strong> cmdlet is that there are four parameter sets to bring a drive online or offline. These parameter sets are shown here.<\/p>\n<p style=\"padding-left: 30px\">Set-Disk [-Number] &lt;UInt32&gt; [-AsJob [&lt;SwitchParameter&gt;]] [-CimSession<\/p>\n<p style=\"padding-left: 30px\">&lt;CimSession[]&gt;] [-IsOffline &lt;Boolean&gt;] [-ThrottleLimit &lt;Int32&gt;]<\/p>\n<p style=\"padding-left: 30px\">[&lt;CommonParameters&gt;]<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Set-Disk [-AsJob [&lt;SwitchParameter&gt;]] [-CimSession &lt;CimSession[]&gt;] [-IsOffline<\/p>\n<p style=\"padding-left: 30px\">&lt;Boolean&gt;] [-ThrottleLimit &lt;Int32&gt;] -Path &lt;String&gt; [&lt;CommonParameters&gt;]<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Set-Disk [-AsJob [&lt;SwitchParameter&gt;]] [-CimSession &lt;CimSession[]&gt;] [-IsOffline<\/p>\n<p style=\"padding-left: 30px\">&lt;Boolean&gt;] [-ThrottleLimit &lt;Int32&gt;] -UniqueId &lt;String&gt; [&lt;CommonParameters&gt;]<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Set-Disk [-AsJob [&lt;SwitchParameter&gt;]] [-CimSession &lt;CimSession[]&gt;] [-IsOffline<\/p>\n<p style=\"padding-left: 30px\">&lt;Boolean&gt;] [-ThrottleLimit &lt;Int32&gt;] -InputObject &lt;CimInstance[]&gt;<\/p>\n<p style=\"padding-left: 30px\">[&lt;CommonParameters&gt;]<\/p>\n<p>Another four parameter sets permit making a drive read-only or not. These are shown here.<\/p>\n<p style=\"padding-left: 30px\">Set-Disk [-Number] &lt;UInt32&gt; [-AsJob [&lt;SwitchParameter&gt;]] [-CimSession<\/p>\n<p style=\"padding-left: 30px\">&lt;CimSession[]&gt;] [-Guid &lt;String&gt;] [-IsReadOnly &lt;Boolean&gt;] [-Signature &lt;UInt32&gt;]<\/p>\n<p style=\"padding-left: 30px\">[-ThrottleLimit &lt;Int32&gt;] [&lt;CommonParameters&gt;]<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Set-Disk [-AsJob [&lt;SwitchParameter&gt;]] [-CimSession &lt;CimSession[]&gt;] [-Guid<\/p>\n<p style=\"padding-left: 30px\">&lt;String&gt;] [-IsReadOnly &lt;Boolean&gt;] [-Signature &lt;UInt32&gt;] [-ThrottleLimit<\/p>\n<p style=\"padding-left: 30px\">&lt;Int32&gt;] -Path &lt;String&gt; [&lt;CommonParameters&gt;]<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Set-Disk [-AsJob [&lt;SwitchParameter&gt;]] [-CimSession &lt;CimSession[]&gt;] [-Guid<\/p>\n<p style=\"padding-left: 30px\">&lt;String&gt;] [-IsReadOnly &lt;Boolean&gt;] [-Signature &lt;UInt32&gt;] [-ThrottleLimit<\/p>\n<p style=\"padding-left: 30px\">&lt;Int32&gt;] -UniqueId &lt;String&gt; [&lt;CommonParameters&gt;]<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Set-Disk [-AsJob [&lt;SwitchParameter&gt;]] [-CimSession &lt;CimSession[]&gt;] [-Guid<\/p>\n<p style=\"padding-left: 30px\">&lt;String&gt;] [-IsReadOnly &lt;Boolean&gt;] [-Signature &lt;UInt32&gt;] [-ThrottleLimit<\/p>\n<p style=\"padding-left: 30px\">&lt;Int32&gt;] -InputObject &lt;CimInstance[]&gt; [&lt;CommonParameters&gt;]<\/p>\n<p>Unfortunately, there are no parameter sets that permit bringing a disk online AND making it read-write at the same time. So if the drive comes online in read-only fashion, I need to use the <strong>Set-Disk<\/strong> cmdlet a second time to make it read-write. This is shown here.<\/p>\n<p style=\"padding-left: 30px\">Get-Disk -FriendlyName *usb* | Set-Disk -IsReadOnly:$false<\/p>\n<p>Of course, I can combine the two commands as a series when bringing the drive online, as shown here.<\/p>\n<p style=\"padding-left: 30px\">Get-Disk | ? IsOffline | Set-Disk -IsOffline:$false<\/p>\n<p style=\"padding-left: 30px\">Get-Disk | ? IsReadOnly | Set-Disk -IsReadOnly:$false<\/p>\n<p>When I am finished uploading pictures to my drive, and I want to put the drive away, I run the command shown here to take the drive offline, so I can unplug it. Here is the command I use.<\/p>\n<p style=\"padding-left: 30px\">Get-Disk -FriendlyName *usb* | Set-Disk -IsOffline:$true<\/p>\n<p>See you tomorrow as the Scripting Wife and I travel to Cern to visit the Particle Accelerator. My blog post will discuss using the CIM cmdlets to explore WMI classes&mdash;it&#8217;s good stuff.<\/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>. 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 to manage disk drives on his Windows&nbsp;8 laptop. Microsoft Scripting Guy, Ed Wilson, is here. Today, the Scripting Wife and I are back in Dortmund, Germany. We will spend the day with Windows PowerShell Guru Klaus Schulte. Our first day in Germany was spent [&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":[374,362,3,12,61,367,45],"class_list":["post-4605","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-disks","tag-powershell-3","tag-scripting-guy","tag-storage","tag-weekend-scripter","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 to manage disk drives on his Windows&nbsp;8 laptop. Microsoft Scripting Guy, Ed Wilson, is here. Today, the Scripting Wife and I are back in Dortmund, Germany. We will spend the day with Windows PowerShell Guru Klaus Schulte. Our first day in Germany was spent [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4605","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=4605"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4605\/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=4605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=4605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=4605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}