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

你。 提交于 2019-11-27 12:43:38

问题


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


回答1:


Try this:

net use * /delete /y

The /y key makes it select Yes in prompt silently



来源:https://stackoverflow.com/questions/13284106/why-net-use-delete-does-not-work-but-waits-for-confirmation-in-my-powershel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!