{"id":4511,"date":"2009-01-27T16:31:00","date_gmt":"2009-01-27T16:31:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2009\/01\/27\/rename-drive-renaming-drives-with-powershell-wmi\/"},"modified":"2019-02-18T13:12:50","modified_gmt":"2019-02-18T20:12:50","slug":"rename-drive-renaming-drives-with-powershell-wmi","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/rename-drive-renaming-drives-with-powershell-wmi\/","title":{"rendered":"Rename-Drive : Renaming Drives with PowerShell &#038; WMI"},"content":{"rendered":"<p>    .CmdletName { font-size:large }\n    .CmdletSynopsis { font-size:medium }\n    .CmdletDescription { font-size:medium }\n    .CmdletParameters { font-size:medium }\n    th {\n        font-size: medium;\n        font-style: italic\n    }\n    table {\n        border: 1\n    }<\/p>\n<p class=\"PostHeader\">Shane Burton from <a href=\"http:\/\/www.compellent.com\/\">Compellent<\/a> just asked me to help him rename a drive with PowerShell. It&#8217;s possible to rename drives using a couple of different WMI classes, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa394515.aspx\">Win32_Volume<\/a>, and <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa394173.aspx\">Win32_LogicalDisk<\/a>. You change the drive by setting a property name on the WMI Object (Label in Win32_Volume, and VolumeName in Win32_LogicalDisk), and then putting it back in the WMI repository with the Put() method. @&#8221;, @&#8221; WMI and PowerShell can do a lot of cool things together. If you want a quick way to search what you can do with WMI in PowerShell, check out an earlier blog post of mine: <a href=\"http:\/\/blogs.msdn.com\/powershell\/archive\/2007\/09\/24\/get-wmihelp-search-wmihelp.aspx\">Get-WmiHelp \/ Search-WMIHelp<\/a>.<\/p>\n<p class=\"PostHeader\">Here&#8217;s my Rename-Drive function:<\/p>\n<p class=\"CmdletName\">Rename-Drive<\/p>\n<p><\/p>\n<p class=\"CmdletSynopsis\"><b>Synopsis:<\/b><\/p>\n<blockquote><p>Renames a drive with WMI <\/p><\/blockquote>\n<p><\/p>\n<p class=\"CmdletSyntax\"><b>Syntax:<\/b><\/p>\n<blockquote><p>Rename-Drive [[-deviceID] [&lt;Object&gt;]] [[-name] [&lt;Object&gt;]] [&lt;CommonParameters&gt;] <\/p><\/blockquote>\n<p><\/p>\n<p class=\"CmdletDescription\"><b>Detailed Description:<\/b><\/p>\n<blockquote><p>Uses the Win32_LogicalDisk class to rename a drive using WMI. Must be running as administrator to use <\/p><\/blockquote>\n<p><\/p>\n<p class=\"Examples\">Examples:<\/p>\n<blockquote>\n<pre class=\"CmdletExample\">    -------------------------- EXAMPLE 1 --------------------------\n# Sets the name of C: to FooBar\nRename-Drive C: FooBar\n    <\/pre>\n<\/blockquote>\n<blockquote>\n<pre class=\"CmdletExample\">    -------------------------- EXAMPLE 2 --------------------------\n# Resets the name of C:\nRename-Drive C:\n    <\/pre>\n<\/blockquote>\n<p><\/p>\n<p>Here&#8217;s Rename-Drive: <i><\/p>\n<blockquote>\n<pre class=\"CmdletDefinition\">function Rename-Drive {\n    #.Synopsis\n    #    Renames a drive with WMI\n    #.Description\n    #    Uses the Win32_LogicalDisk class to rename a drive using WMI.  Must be running as administrator to use\n    #.Example\n    #    # Sets the name of C: to FooBar\n    #    Rename-Drive C: FooBar\n    #.Example\n    #    # Resets the name of C:\n    #    Rename-Drive C:\n    param($deviceID = \"C:\", $name)\n$drive = Get-WmiObject \"Win32_LogicalDisk WHERE DeviceID='$deviceID'\"\n    if (-not $drive) { return }\n    $drive.VolumeName = $name\n    $null = $drive.Put()\n}\n    <\/pre>\n<\/blockquote>\n<p><\/i><\/p>\n<p class=\"Postfooter\">Hope This Helps,<\/p>\n<p class=\"Postfooter\">James Brundage [MSFT]<\/p>\n<p>Automatically generated with <a href=\"http:\/\/blogs.msdn.com\/powershell\/archive\/tags\/Write-CommandBlogPost\/default.aspx\">Write-CommandBlogPost<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>.CmdletName { font-size:large } .CmdletSynopsis { font-size:medium } .CmdletDescription { font-size:medium } .CmdletParameters { font-size:medium } th { font-size: medium; font-style: italic } table { border: 1 } Shane Burton from Compellent just asked me to help him rename a drive with PowerShell. It&#8217;s possible to rename drives using a couple of different WMI classes, [&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":[26],"class_list":["post-4511","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>.CmdletName { font-size:large } .CmdletSynopsis { font-size:medium } .CmdletDescription { font-size:medium } .CmdletParameters { font-size:medium } th { font-size: medium; font-style: italic } table { border: 1 } Shane Burton from Compellent just asked me to help him rename a drive with PowerShell. It&#8217;s possible to rename drives using a couple of different WMI classes, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4511","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=4511"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4511\/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=4511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=4511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=4511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}