0

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.

The script returns true to the Z drive folder existing but won't map to the network drive. The error I receive is

Exception calling "MapNetworkDrive" with "5" argument(s): "The specified device name is invalid.

All help would be greatly appreciated.

[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)
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
Edward Muldrew
  • 253
  • 1
  • 6
  • 20
  • 2
    `$drive = "Z:"` perhaps. Most examples don't have the trailing slash. Also might be better to use something like `New-PSDrive` – Matt Nov 16 '18 at 14:57
  • @Matt Hi Matt, that fixed that error! I receive another error saying "The local device name has a remembered connection to another network resource." Would you know anything about this? – Edward Muldrew Nov 16 '18 at 15:00
  • 3
    Yes. You can't have connections to the same resource as different users. You can cheat that if you need to by specifying the IP address for the other resource. Windows will see that as two distinct targets. – Matt Nov 16 '18 at 15:03
  • @Matt Just to clarify my understanding of this. Does this mean the Z:\ folder has multiple connections to it and windows does not like it? If so how would I be able to check what what users have connections to this resource? – Edward Muldrew Nov 16 '18 at 15:07
  • 1
    https://stackoverflow.com/questions/9037503/determine-domain-and-username-used-to-map-a-network-drive – Matt Nov 16 '18 at 15:09

0 Answers0