Discussion:
Remove-PSDrive fails - need help
(too old to reply)
FredM
2008-09-30 15:00:20 UTC
Permalink
I have a drive mapped as T: that happens automatically when I log in.

When I try the following PowerShell script to unmap that drive,

Remove-PSDrive 'T' -WhatIf

I get an error saying:

Cannot find drive. A drive with name 'T' does not exist.

However, Get-PSDrive clearly shows that T does in fact exist, so I'm
mystified why one part of PowerShell (Get-PSDrive) can see the T drive but
the other side (Remove-PSDrive) cannot.

All of the following fail with the same error message:

Remove-PSDrive T -WhatIf

Remove-PSDrive -Name T -WhatIf

Remove-PSDrive -Name 'T' -WhatIf

Remove-PSDrive -LiteralName 'T' -WhatIf

Remove-PSDrive t -WhatIf

Remove-PSDrive -Name t -WhatIf

Remove-PSDrive -Name 't' -WhatIf

Remove-PSDrive -LiteralName 't' -WhatIf

What else can I try besides removing -WhatIf at the end? I don't want to
run this for real (without -WhatIf) until I know it has a real chance of
running.
Marco Shaw [MVP]
2008-09-30 15:30:13 UTC
Permalink
Post by FredM
I have a drive mapped as T: that happens automatically when I log in.
When I try the following PowerShell script to unmap that drive,
Remove-PSDrive 'T' -WhatIf
Cannot find drive. A drive with name 'T' does not exist.
However, Get-PSDrive clearly shows that T does in fact exist, so I'm
mystified why one part of PowerShell (Get-PSDrive) can see the T drive but
the other side (Remove-PSDrive) cannot.
I have v2 CTP2, and "help remove-psdrive" says:
...
Remove-PsDrive cannot delete Windows drives or mapped network drives
created by using other methods.
...

So, it looks like PowerShell *cannot* remove that drive even if you want
it to.

Marco
--
*Microsoft MVP - Windows Server - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw
*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com
FredM
2008-09-30 16:25:02 UTC
Permalink
Thanks. I won't beat my head against the wall any more trying to make this
happen via PowerShell.

Some good old fashioned 20th Century Windows C++ programming will do what I
need, but I was hoping to use a 21rst-century technique like PowerShell to
avoid having to drag out Visual Studio and writing code to do what I hoped a
few lines of PowerShell would do using out of the box functionality.

Perhaps this might happen in PowerShell V3?
Post by Marco Shaw [MVP]
Post by FredM
I have a drive mapped as T: that happens automatically when I log in.
When I try the following PowerShell script to unmap that drive,
Remove-PSDrive 'T' -WhatIf
Cannot find drive. A drive with name 'T' does not exist.
However, Get-PSDrive clearly shows that T does in fact exist, so I'm
mystified why one part of PowerShell (Get-PSDrive) can see the T drive but
the other side (Remove-PSDrive) cannot.
....
Remove-PsDrive cannot delete Windows drives or mapped network drives
created by using other methods.
....
So, it looks like PowerShell *cannot* remove that drive even if you want
it to.
Marco
--
*Microsoft MVP - Windows Server - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw
*PowerShell Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com
Karl Mitschke
2008-09-30 17:59:07 UTC
Permalink
Hello FredM,
Post by FredM
I have a drive mapped as T: that happens automatically when I log in.
When I try the following PowerShell script to unmap that drive,
Remove-PSDrive 'T' -WhatIf
Cannot find drive. A drive with name 'T' does not exist.
I assume this is not a drive mapped my New-PSDrive?

If I am correct, try this:

$net = New-Object -com WScript.Network
$net.RemoveNetworkDrive(T:)
OldDog
2008-11-10 19:08:54 UTC
Permalink
Post by Karl Mitschke
Hello FredM,
Post by FredM
I have a drive mapped as T: that happens automatically when I log in.
When I try the following PowerShell script to unmap that drive,
Remove-PSDrive 'T' -WhatIf
Cannot find drive. A drive with name 'T' does not exist.
I assume this is not a drive mapped my New-PSDrive?
$net = New-Object -com WScript.Network
$net.RemoveNetworkDrive(T:)
You will need " " around the drive letter.

$net = New-Object -com WScript.Network
$net.RemoveNetworkDrive("T:")
e***@gmail.com
2014-05-16 20:14:04 UTC
Permalink
Post by OldDog
Post by Karl Mitschke
Hello FredM,
Post by FredM
I have a drive mapped as T: that happens automatically when I log in.
When I try the following PowerShell script to unmap that drive,
Remove-PSDrive 'T' -WhatIf
Cannot find drive. A drive with name 'T' does not exist.
I assume this is not a drive mapped my New-PSDrive?
$net = New-Object -com WScript.Network
$net.RemoveNetworkDrive(T:)
You will need " " around the drive letter.
$net = New-Object -com WScript.Network
$net.RemoveNetworkDrive("T:")
I have a similar problem, and if I execute this i get an error, it says "RemoveNetworkDrive" with "1" argument(s): "This network connection does not exist.
Joe Morris
2014-05-16 23:19:29 UTC
Permalink
[attributions are scrambled]
Post by e***@gmail.com
Post by FredM
I have a drive mapped as T: that happens automatically when I log in.
When I try the following PowerShell script to unmap that drive,
Remove-PSDrive 'T' -WhatIf
Cannot find drive. A drive with name 'T' does not exist.
I have a similar problem, and if I execute this i get an error,
it says "RemoveNetworkDrive" with "1" argument(s): "This network
connection does not exist.
Assuming that you're using Vista or later, if you attempted to disconnect
the drive from an elevated prompt, try it from a non-elevated prompt, and
vice-versa. A attached remote disk is visible only in the context (elevated
or not) in which it was attached.

From a traditional command prompt (elevated or not) the command would be

net use t: /delete


Joe
p***@gmail.com
2017-06-04 00:40:02 UTC
Permalink
Update for PS3:
'help remove-psdrive' returns the following message

...
Starting in Windows PowerShell 3.0, Remove-PSDrive also disconnects mapped
network drives, including, but not limited to, drives created by using the
Persist parameter of New-PSDrive . Remove-PSDrive cannot delete Windows
physical or logical drives.
...

Loading...