title: Using a mapped drive in powershell not working
body: <p>We have 2008 R2 and I'm writing a PowerShell script to copy files to a network share.  Unfortunately, it appears that there is a PowerShell issue with mapped drives.  It looks like someone found a workaround <a href="https://stackoverflow.com/questions/4742992/cannot-access-network-drive-in-powershell-running-as-administrator">poss fix</a>, but I'm not understanding it, or something I have is different than this example.  Has anyone had any luck with this?  Our network drive is mapped in My Computer like this:  </p>
  
  <pre><code>20xServerBackup (\\usa0xxxx.na.xxx.net)(Z:)
  </code></pre>
  
  <p>I've tried a few things in my script, but this is how it looks right now:</p>
  
  <pre><code>runas /user:administrator net use Y: "\\usa0xxxx.na.xxx.net"
  
  $ToLocation = "Y:\VMs\name"
  
  $FromLocation = "C:\backup\iceCreamCake.txt"
  
  Copy-Item "$FromLocation" "$ToLocation"
  </code></pre>
  
  <p>The error I get on the copy line is</p>
  
  <blockquote>
    <p>Copy-Item: Cannot find drive.  A drive with the name 'Y' does not
    exist.</p>
  </blockquote>
  
  <p>I'm not sure where to find what version of powerShell I have, if that makes a difference.  But, I'm pretty sure I upgraded to version 3.0 last week to use the hyperV get-vm/start/stop vm functionality.  </p>
  
  <p>It sounds like the Microsoft website lists this as an active error/problem, but it sounds like someone had a workaround on this (stackoverflow) website, link above, but I'm not sure why it's not working for me.  When I first mapped the drive yesterday, my script was running and copying files to the network share.  Today it isn't, even after a reboot.  I tried re-mapping the drive with a new name and it didn't work any different.  I've tried using the Z drive in my code instead of the Y drive as I created in my script above, and it didn't work any differently.  It still had the same error message.  </p>
  
  <p>I also tried </p>
  
  <pre><code>New-PSDrive -Name YY -PSProvider FileSystem -root "\\usa0xxxx.na.xxx.net"
  </code></pre>
  
  <p>at the powerShell command line.  I'm not sure if I got everything right in that command. It said this error</p>
  
  <blockquote>
    <p>New-PSDrive: Drive root "\usa0xxxx.na.xxx.net" does not exist or it
    is not a folder.</p>
  </blockquote>