简体   繁体   English

如何使用Powershell删除映射的网络驱动器?

[英]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: 例子:

  • File system: Get-ChildItem C: 文件系统: Get-ChildItem C:
  • Registry: Get-ChildItem HKCU: 注册表: Get-ChildItem HKCU:
  • Certificate Store: 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.

相关问题 Powershell / Batch网络映射驱动器 - Powershell/Batch network mapped drive 使用随机字母创建时如何删除映射的网络驱动器 - How to remove mapped network drive when created with a random letter Powershell通过映射的网络驱动器删除sharepoint在线库中的所有文件扩展名 - Powershell to remove all file extensions in sharepoint online library through mapped network drive 无法使用PowerShell删除网络驱动器上的目录 - Unable to remove a directory on network drive with PowerShell PowerShell 脚本将文件从映射的网络驱动器复制到相同映射的网络驱动器的子文件夹,然后将日期添加到文件名 - PowerShell script to copy a file from a Mapped Network Drive to a Subfolder of the same mapped, network drive then add the date to the file name 识别未使用的网络映射驱动器 - Identify unused network mapped drive Powershell检测到额外的映射驱动器 - Powershell detecting an extra mapped drive powershell 在 gpo 上创建映射驱动器 - powershell to create mapped drive on gpo 如何从.NET文件对话框获取映射的网络驱动器的路径 - How to obtain path with mapped network drive from .NET file dialog PowerShell 如何从网络驱动器访问文件? - PowerShell How to access a file from a network drive?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM