Windows – How to set location to a mapped network drive in PowerShell

networkingpowershellwindows 7

I'm trying to set location to mapped network drive Z in PowerShell and it's not working.

I have the following drive letters: C, D, E, Z. Where the first three are just local disks, and the Z is of course the network location mapped to the letter Z.

I can switch from C to D, to E, back to C again, but I cannot for the love of God switch to Z letter for some reason. I can however switch to that location, but I have to type in the network location instead of using the drive letter.

PS C:\Windows\system32> D:
PS D:\> C:
PS C:\Windows\system32> Z:
Set-Location : Cannot find drive. A drive with the name 'Z' does not exist.
At line:1 char:13
+ Set-Location <<<<  Z:
    + CategoryInfo          : ObjectNotFound: (Z:String) [Set-Location], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

PS C:\Windows\system32> Set-Location \\fileserver\karta
PS Microsoft.PowerShell.Core\FileSystem::\\fileserver\karta> C:
PS C:\Windows\system32> Z:
Set-Location : Cannot find drive. A drive with the name 'Z' does not exist.
At line:1 char:13
+ Set-Location <<<<  Z:
    + CategoryInfo          : ObjectNotFound: (Z:String) [Set-Location], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

PS C:\Windows\system32> Set-Location Z:
Set-Location : Cannot find drive. A drive with the name 'Z' does not exist.
At line:1 char:13
+ Set-Location <<<<  Z:
    + CategoryInfo          : ObjectNotFound: (Z:String) [Set-Location], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

PS C:\Windows\system32>

a

Why is it not working? Is this not supported in PowerShell… using drive letters to set location to a network location?

Best Answer

The problem you're running into is because the Z: drive is mapped in your user's context, but not in the "administrator" context.

So when you run PowerShell "As Administrator" the Z: drive (map) doesn't exist and if you want it, you'd have to create it in that context for it to be available.

Related Question