Orphaned Powershell PSDrive

I received this strange error while executing a script that creates a new PSDrive.

New-PSDrive : The local device name has a remembered connection to another network resource

I tried to use Remove-PSDrive, but

Remove-PSDrive : Cannot find drive. A drive with the name 'S:' does not exist.

I was able to fix this issue with the “net use” command.

First, I ran it to see if the drive was still mapped. I am still unsure how it is there between Powershell sessions, I must have missed something.

PS C:\> net use
New connections will be remembered.

Status Local Remote Network
------------------------------------------------------------------------------
Unavailable S: \\node1\d\$ Microsoft Windows Network
Unavailable I: \\node2\it Microsoft Windows Network
OK P: \\public Microsoft Windows Network
The command completed successfully.

Then I ran “net use” with the delete parameter to remove the orphaned drive.

PS C:\> net use /delete S:
S: was deleted successfully.

I love it when a plan comes together.

3 comments

1. nemo

Well, that is one way to do it. But I blieve there also should be a PS way. I had Remove-PSDrive working from the PowerShell, but not inside a script. Maybe scope. Still working on that. But you might want to know that your Remove-PSDrive probably didn’t work because of the colon. Remove-PSDrive should be called with just the drive letter.

• Charles

Thanks for the comment. The reason for the post is that I couldn’t do it with the PS commands. The colon next to the commands in the post are from the error message, and is not an example of how I ran the command. The command was used with just the drive letter as indicated in the error message that I posted.