title: How to change drive label using Powershell?
body: <p>I'm trying to mount a couple of network drives and then rename them. However my Powershell script is failing after the first drive renames fine. For the second one I get an error:</p>
  
  <pre><code>Exception calling "Put" with "0" argument(s): ""
  At C:\Users\ben\Documents\mapdrives.ps1:12 char:11
  + $disk.Put &lt;&lt;&lt;&lt; ()
  + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
  + FullyQualifiedErrorId : DotNetMethodException
  </code></pre>
  
  <p>My script looks like this:</p>
  
  <pre><code>cls
  $Username = ""
  $Password = ""
  $net = New-Object -com WScript.Network; 
  
  $Drive = "M:"
  $UNC = "\\server01\bin$"
  $net.mapnetworkdrive($Drive, $Unc, $false, $Username, $Password)
  $disk = Get-WmiObject "Win32_LogicalDisk WHERE DeviceID='M:'"
  if (-not $disk) { return }
  $disk.VolumeName = "server1_bin"
  $disk.Put()
  
  $Drive = "N:"
  $UNC = "\\server01\data$"
  $net.mapnetworkdrive($Drive, $Unc, $false, $Username, $Password)
  $disk = Get-WmiObject "Win32_LogicalDisk WHERE DeviceID='N:'"
  if (-not $disk) { return }
  $disk.VolumeName = "server1_data"
  $disk.Put()
  </code></pre>
  
  <p>What am I doing wrong?</p>