To create a mapped network drive in Powershell, you use:
New-PSDrive -Name “S” -Root “\\Server01\Scripts” -Persist -PSProvider “FileSystem”
Although this is meant for remote servers, I tried referring the local machine as a server and it worked.
New-PSDrive -Name “S” -Root “\\localhost\Scripts” -Persist -PSProvider “FileSystem”
The only drawback was there’s no entry in File Explorer (you shouldn’t be using that anyway). Additionally, a problem was found trying to remove this new drive:
Get-PSDrive -Name S | Remove-PSDrive -force
Nope, drive still shows in Get-PSDrive
Remove-PSDrive -Name S -PSProvider FileSystem -Force
Nope, still there.
Net Use S: /del (old school command)
Funny thing though. Retrying this exercise a second time created the drive as before but now Get-PSDrive S | Remove-PSDrive -force worked just fine.
Live and learn I guess…
tags: Mapped Drive, drive, drives, mapping drives, Remove-PSDrive, Get-PSDrive, Powershell