如何使用 PowerShell 刪除對映的網路驅動器?


若要在 Windows 系統上從 PowerShell 中刪除對映的驅動器,你可以使用 PowerShell 和 cmd 命令。

使用 cmd 命令

你可以使用以下命令,透過指定磁碟驅動器磁碟機代號或使用萬用字元 (*) 來刪除單個對映的驅動器。

若要刪除單個對映的驅動器。

示例

net use K: /delete

輸出

PS C:\WINDOWS\system32> net use K: /delete
K: was deleted successfully.

若要同時刪除多個對映的驅動器。

示例

net use * /delete

你需要確認同時刪除多個對映的磁碟。

輸出

PS C:\WINDOWS\system32> net use * /delete
You have these remote connections:

    K:              \remoteshare\shared
    M:              \remoteshare\shared folder
Continuing will cancel the connections.

Do you want to continue this operation? (Y/N) [N]: Y
The command completed successfully.

使用 PowerShell 方法

若要使用 PowerShell 命令刪除對映的網路驅動器,你需要在 cmdlet 中提供驅動器磁碟機代號。如果你想同時刪除多個驅動器,請用逗號 (,) 將它們分開。

Remove-PSDrive K,M –Force -Verbose

PS C:\WINDOWS\system32> Remove-PSDrive K,M -Force -Verbose
VERBOSE: Performing the operation "Remove Drive" on target "Name: K Provider: Microsoft.PowerShell.Core\FileSystem Root: K:\".
VERBOSE: Performing the operation "Remove Drive" on target "Name: M Provider: Microsoft.PowerShell.Core\FileSystem Root: M:\".

或者,你可以使用 Get-PSDrive 獲取對映的驅動器,並使用管道 Remove-PSDrive 命令來刪除它們。

Get-PSDrive K,M | Remove-PSDrive -Force -Verbose

輸出

PS C:\WINDOWS\system32> Get-PSDrive K,M | Remove-PSDrive -Force -Verbose
VERBOSE: Performing the operation "Remove Drive" on target "Name: K Provider: Microsoft.PowerShell.Core\FileSystem Root: K:\".
VERBOSE: Performing the operation "Remove Drive" on target "Name: M Provider: Microsoft.PowerShell.Core\FileSystem Root: M:\".

更新於: 2020 年 11 月 11 日

14K+ 次瀏覽

開啟您的 事業

透過完成課程獲得認證

開始吧
廣告
© . All rights reserved.