如何使用 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.