Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to disconnect a network drive (Y:) with powershell. That drive letter is assigned / mapped to a network location. Is there a simple way to do that?

I believe "net use XXX /delete" would do that.

The problem is:

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

Status       Local     Remote                    Network

OK           Y:        \\\d         Microsoft Windows Network
The command completed successfully.

why when I try:

C:\Windows>net use \\\d  /del

I get:

C:\Windows>net use \\\d  /del
The network connection could not be found.

More help is available by typing NET HELPMSG 2250.


share|improve this question
up vote 6 down vote accepted

In powershell you could issue a set of commands like this to disconnect a drive, given only the UNC that you used to connect, and not knowing the drive letter that was mapped.

The tricky part is that you have to escape the \ character to use it in the WMI query.

$Drive = Get-WmiObject -Class Win32_mappedLogicalDisk -filter "ProviderName='\\\\\\d'"
net use $Drive.Name /delete
share|improve this answer
Add /y to net use $Drive.Name /delete to force close any open connections on the drive. If there are open connections, net use will prompt for action which you don't want in the middle of an unattended script run. – Alan Donnelly Jan 4 '15 at 15:58

I would like to suggest using PowerShell's own Remove-PSDrive. For example:

Remove-PSDrive Y

I didn't need a colon or a backslash, just plain Y.

share|improve this answer
Remove-psdrive Y will not completely remove the drive and will leave a network drive mapping which will throw an error when you try to re-create the the ps-drive in the same session. You have to use net use /delete in order to negate this issue. it would be nice if the powershell remove-psdrive command actually removed the drive. – user269317 Nov 4 '13 at 10:54

Changed my answer based on your comment

Net use Y: /delete

share|improve this answer
I believe i've not expressed myself good. What I want is to remove the drive from windows explorer. – FernandoSBS May 21 '13 at 23:24
and if I want to use the network address to do it? – FernandoSBS May 21 '13 at 23:41
you cant, you are disconnecting a drive, not a share – Keltari May 21 '13 at 23:42
check initial post please – FernandoSBS May 21 '13 at 23:45
reword your initial post cause what Keltari said is right. What he said will remove the drive from windows explorer – Jason H May 21 '13 at 23:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.