Why “net use * /delete” does not work but waits for confirmation in my PowerShell script?

Asked by on 2012-11-08T02:11:38-05:00
I have a script where I want to disconnect from the mapped drives before I create a new PSDrive.

Otherwise I get this error:

New-PSDrive : Multiple connections to a server or shared resource by the same user , using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again

So I have this line:

net use * /delete
(Unfortunately I could not find a way to disconnect from a specific mapped drive just by providing the server name so far :( )

When PS comes to this line

You have these remote connections:

 \\ServerName\\SharedFolder Continuing will cancel the connections.
And then it stops executing.

Is there a way to auto confirm disconnecting from the mapped drives automatically without confirmation (it does not have to be the net use /delete solution)?

Note that: I run my script from the Powershell ISE PS promt

Best Answer

Answered by on 2012-11-08T02:34:40-05:00
Try this:

Net use * /delete /y
Your Answer
No advertising and No spamming please.
Name:
Answer:

All Answers

Answered by on 2012-12-05T09:33:56-05:00
net use * /delete /yes
Can't add a comment to the answer above so added an extra answer.