Remove-PSDrive fails - need help

2469 views
Skip to first unread message

FredM

unread,
Sep 30, 2008, 11:00:20 AM9/30/08
to
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]

unread,
Sep 30, 2008, 11:30:13 AM9/30/08
to
FredM wrote:
> 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.

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

unread,
Sep 30, 2008, 12:25:02 PM9/30/08
to
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?

"Marco Shaw [MVP]" wrote:

> FredM wrote:
> > 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.
>
> I have v2 CTP2, and "help remove-psdrive" says:

> ....


> Remove-PsDrive cannot delete Windows drives or mapped network drives
> created by using other methods.

> ....

Karl Mitschke

unread,
Sep 30, 2008, 1:59:07 PM9/30/08
to
Hello 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
>
> I get an error saying:
>
> 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

unread,
Nov 10, 2008, 2:08:54 PM11/10/08
to

You will need " " around the drive letter.

edga...@gmail.com

unread,
May 16, 2014, 4:14:04 PM5/16/14
to
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

unread,
May 16, 2014, 7:19:29 PM5/16/14
to
<edga...@gmail.com> wrote:
El lunes, 10 de noviembre de 2008 13:08:54 UTC-6, OldDog escribi�:
> On Sep 30, 11:59 am, Karl Mitschke <kmitsc...@somestate.gov> wrote:

[attributions are scrambled]

> > > 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.

>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


physike...@gmail.com

unread,
Jun 3, 2017, 8:40:04 PM6/3/17
to
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.
...
Reply all
Reply to author
Forward
0 new messages