Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 228
pencilCake Avatar asked Nov 08 '12 07:11

pencilCake


People also ask

How do I clear net use?

You can use the Net Use * /delete command to delete active connections on a local computer. The command deletes all the active connections on local computer. This command can also be used on remote computers.


1 Answers

Try this:

net use * /delete /y 

The /y key makes it select Yes in prompt silently

like image 190
Nick Avatar answered Sep 19 '22 05:09

Nick