Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:        \\192.168.1.108\d         Microsoft Windows Network
The command completed successfully.

why when I try:

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

I get:

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

More help is available by typing NET HELPMSG 2250.

????

share|improve this question
add comment

3 Answers

up vote 4 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='\\\\192.168.1.108\\d'"
net use $Drive.Name /delete
share|improve this answer
add comment

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
add comment

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
show 1 more comment

Your Answer

 
discard

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.