【问题标题】:How to remove mapped network drive with Powershell?如何使用 Powershell 删除映射的网络驱动器?
【发布时间】:2018-11-19 09:52:12
【问题描述】:

我正在尝试使用 PowerShell 创建和删除新的映射网络驱动器。

它会创建映射驱动器,但我似乎无法删除映射驱动器。我收到的错误信息是:

目录:找不到路径“C:\Windows\system32\P”,因为它不存在。

New-PSDrive -Name "P" -Root "\\VM-Blue-Robin\Testing" -Persist -PSProvider "FileSystem" 
#Get-PSDrive P | Remove-PSDrive
#Remove-PSDrive -Name P -Force
#Remove-PSDrive P, Z

到目前为止,所有 Google 和 Stack Overflow 向我建议的都是使用我之前注释掉的命令。我不确定自己做错了什么,但感觉可能可以对我的文件位置进行处理?

所有帮助将不胜感激!

【问题讨论】:

  • 您是否收到任何使用 Remove-PSDrive 的特定错误消息?
  • @TobyU 它是目录:找不到路径'C:\Windows\system32\P',因为它不存在。但是,当我运行 Dir P 或 Get-PSDrive 时。我可以看到驱动器确实存在
  • 如果您打算尽快移除驱动器,为什么要添加-Persist 参数,然后我会添加-Sope 以尽量减少可能的其他进程介入。
  • 该错误是因为您运行的是dir P 而不是dir P: 您需要: 来表示驱动器而不是文件夹。

标签: powershell


【解决方案1】:

错误是因为您运行的是dir P 而不是dir P: 您需要: 来表示驱动器而不是文件夹。

dir(在 Powershell 中实际上是 Get-ChildItem 的别名)可以读取操作系统的多个区域,因此您需要更具体地告诉它。

例子:

  • 文件系统:Get-ChildItem C:
  • 注册:Get-ChildItem HKCU:
  • 证书商店:Get-ChildItem cert:

虽然使用Get/Remove-PSDrive 命令,但您明确告诉它您想要一个"FileSystem" 驱动器,因此它知道Name 是一个驱动器号。


关于删除驱动器,您列出的两个命令中的任何一个都可以正常工作:

New-PSDrive -Name P -Root "\\VM-Blue-Robin\Testing" -Persist -PSProvider "FileSystem" 

Get-PSDrive P | Remove-PSDrive
Remove-PSDrive -Name P -Force

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-18
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 2019-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多