How to set location to a mapped network drive in PowerShell?

5

1

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?

Samir

Posted 2014-04-07T13:29:42.543

Reputation: 17 919

Just for the record I am running x86 version of PowerShell with admin elevation on x64 Windows 7. – Samir – 2014-04-07T13:36:34.420

That is very odd, I can't seem to replicate the issue. Does it work without admin elevation? – Alex McKenzie – 2014-04-07T13:58:55.083

@AlexMcKenzie Yup! It worked without admin elevation!? So what's the issue then?... – Samir – 2014-04-07T14:11:46.100

Answers

10

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.

Ƭᴇcʜιᴇ007

Posted 2014-04-07T13:29:42.543

Reputation: 103 763

1This is exactly the problem I was running into... I mapped my network drives in a non-elevated PS session, and tried accessing them from an elevated session. If you re-map your network drives in an elevated context, you should be good! – qJake – 2014-08-18T14:54:34.270