0

Mapped network drive with

New-PsDrive -Name Z -PSProvider filesystem -Root "\\localhost\C$\Users\Keith\Documents\Project" -Persist

In cmd and powershell I can navigate to Z:\, but the drive does not appear in file explorer and I cannot navigate to the drive in file explorer. Any solutions?

2 Answers2

1

PSDrive isn't intended for this purpose.

You can use a simple cmd era solution:

net use Z: "\\localhost\C$\Users\Keith\Documents\Project" /persistent:yes

A COM and PS solution:

$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive("Z:", "\\localhost\C$\Users\Keith\Documents\Project")

You can check here for further details: Powershell: how to map a network drive with a different username/password

Matt R
  • 398
  • 2
  • 5
  • OP specifically aske to do this in powershell, so running a command in/via CMD is *cheating*. There must be a good solution for using pwsh. The MS documents for these commands are simply not showing reality. – not2qubit Jun 30 '22 at 14:12
0

when you run the command in an elevated powershell (as administrator) your user account logged on does not see the drive. but if you run a "normal" powershell and run the command there the drive is displayed as expected. make sure you use the correct user account.

Guenther Schmitz
  • 1,955
  • 1
  • 9
  • 23