我正在尝试使用PowerShell创建和删除新的映射网络驱动器。
它会创建映射的驱动器,但是我似乎无法删除映射的驱动器。我收到的错误消息是:
Dir:找不到路径'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向我建议的都是使用我之前注释掉的命令。我不确定自己在做什么错,但是感觉可以对文件的位置进行处理吗?
所有帮助将不胜感激!
答案 0 :(得分:3)
错误是因为您运行的是dir P
而不是dir P:
,因此您需要:
来表示驱动器而不是文件夹。
dir
(在Powershell中实际上是Get-ChildItem
的别名)可以读取OS的多个区域,因此您需要更具体地说明内容。
示例:
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