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.
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
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.
> ....
> 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:)
You will need " " around the drive letter.