2012-11-08 71 views
27

我有一個腳本,我想在創建新的PSDrive之前從映射驅動器斷開連接。只是通過提供服務器爲什麼「net use */delete」不起作用,但等待PowerShell腳本中的確認?

net use * /delete 

(可惜我不能找到一種方法,從一個特定的映射驅動器斷開:

否則我得到這個錯誤:

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

所以我有這條線名字至今:()

當PS談到此行

You have these remote connections:

\\ServerName\SharedFolder Continuing will cancel the connections.

然後停止執行。

有沒有一種方法可以自動確認從映射驅動器斷開連接而無需確認(它不必是淨使用/刪除解決方案)?

注意:我從運行PowerShell ISE中PS我的腳本PROMT

回答

74

試試這個:

net use * /delete /y 

/y鍵使得它在提示默默

+0

並選擇是'/沒有'選中否提示默默。 –

+0

非常感謝你。工作很好! –

相關問題