[英]How to remove mapped network drive with Powershell?
I am trying to create and remove a new mapped network drive using PowerShell. 我正在尝试使用PowerShell创建和删除新的映射的网络驱动器。
It creates the mapped drive, however I can't seem to remove the mapped drive. 它创建了映射的驱动器,但是我似乎无法删除映射的驱动器。 The error message I receive is:
我收到的错误消息是:
Dir : Cannot find path 'C:\\Windows\\system32\\P' because it does not exist.
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
All Google and Stack Overflow has suggested to me thus far is using the commands that I have previously commented out. 到目前为止,所有Google和Stack Overflow对我的建议都是使用我之前注释掉的命令。 I am unsure of what I am doing wrong but had a feeling it could be done to the location of my files perhaps?
我不确定自己在做什么错,但是感觉可以对文件的位置进行处理吗?
All help would be greatly appreciated! 所有帮助将不胜感激!
The error is because you're running dir P
instead of dir P:
You need the :
to signify a drive not a folder. 该错误是因为您运行的是
dir P
而不是dir P:
您需要使用:
来表示驱动器而不是文件夹。
dir
(which in Powershell is a actually an alias for Get-ChildItem
) can read multiple areas of the OS so you need to be more specific with what you tell it. dir
(在Powershell中实际上是Get-ChildItem
的别名)可以读取操作系统的多个区域,因此您需要更具体地说明内容。
Examples: 例子:
Get-ChildItem C:
Get-ChildItem C:
Get-ChildItem HKCU:
Get-ChildItem HKCU:
Get-ChildItem cert:
Get-ChildItem cert:
Whilst with Get/Remove-PSDrive
commands you are specifically telling it you want a "FileSystem"
drive so it knows that Name
is a drive letter. 使用
Get/Remove-PSDrive
命令时,您特别要告诉它您想要一个"FileSystem"
驱动器,以便它知道Name
是驱动器号。
With regards to removing the drive, either of the two commands you've listed will work fine: 关于卸下驱动器,您列出的两个命令都可以正常工作:
New-PSDrive -Name P -Root "\\VM-Blue-Robin\Testing" -Persist -PSProvider "FileSystem"
Get-PSDrive P | Remove-PSDrive
Remove-PSDrive -Name P -Force
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.