Access already mapped network drive in PowerShell
Solution 1:
You need to make the drive mapping available to the user you're running Powershell
as. You can do the following to give that user the same drive mapping:
net use Z: "\\vmware-host\Shared Folders"
See the following SO question: Cannot access network drive in PowerShell running as administrator
Solution 2:
Are you starting this PowerShell console as Administrator or as your current user?
If you are running it from a non-elevated command prompt, then it should see all your locally mapped network drives. I'm in the same situation as you right now and have x:
mapped to \\vmware-host\[folder]
, and a Get-PSDrive -PSProvider FileSystem
shows me all my locally mapped drives.
However, if I start this console as an Administrator, it does not see any of my local mapped drive, as for an elevated command prompt a different (second) security context is used to load the application, which does not share network connections.
The good news is that you basically just need to map the drive in the administrator console just once and it will remain in that security context (until a reboot, I think).
If you want to automate this, you should read up on auto-loading scripts when you start a powershell session. Basically if you create a folder in your My Documents
called WindowsPowerShell
and inside that create a Microsoft.PowerShell_profile.ps1
file, it will trigger every time you start a new powershell console. There you can add a net use
command, or add custom functions that you've written that you want to use.
For example, I have one that turns my cursor red for administrative consoles, and has a function that I can easily call to sign my PS1 scripts.