title: How to map to a network drive using a Powershell script
body: <p>I am trying to create a powershell to connect to a network drive. I have researched various sources on the internet and Stack Overflow but has yet to work.</p>
  
  <p>The script returns true to the Z drive folder existing but won't map to the network drive. The error I receive is </p>
  
  <blockquote>
    <p>Exception calling "MapNetworkDrive" with "5" argument(s): "The specified device name is invalid.</p>
  </blockquote>
  
  <p>All help would be greatly appreciated. </p>
  
  <pre><code>[System.IO.Directory]::Exists('Z:\Output');
  $user = "domain\username"
  $password = "password"
  $drive = "Z:\"
  $path = "\\Output"
  
  $map = new-object -ComObject WScript.Network
  $map.MapNetworkDrive($drive,$path ,$false, $user, $password)
  </code></pre>