Remove-PSDrive

删除临时 PowerShell 驱动器并断开映射网络驱动器的连接。

语法

Remove-PSDrive
      [-Name] <String[]>
      [-PSProvider <String[]>]
      [-Scope <String>]
      [-Force]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]
Remove-PSDrive
      [-LiteralName] <String[]>
      [-PSProvider <String[]>]
      [-Scope <String>]
      [-Force]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]

说明

cmdlet Remove-PSDrive 删除使用 New-PSDrive cmdlet 创建的临时 PowerShell 驱动器。

从 Windows PowerShell 3.0 开始,Remove-PSDrive还会断开映射的网络驱动器的连接,包括但不限于使用 Persist 的 参数New-PSDrive创建的驱动器。

Remove-PSDrive 无法删除 Windows 物理驱动器或逻辑驱动器。

从 Windows PowerShell 3.0 开始,当外部驱动器连接到计算机时,PowerShell 会自动将 PSDrive 添加到表示新驱动器的文件系统。 无需重启 PowerShell。 同样,当外部驱动器与计算机断开连接时,PowerShell 会自动删除表示已删除驱动器的 PSDrive。

示例

示例 1:删除文件系统驱动器

此命令删除一个名为“smp”的临时文件系统驱动器。

Remove-PSDrive -Name smp

示例 2:删除映射的网络驱动器

此命令使用 Remove-PSDrive 断开 X: 和 S: 映射的网络驱动器的连接。

Get-PSDrive X, S | Remove-PSDrive

参数

-Confirm

提示你在运行 cmdlet 之前进行确认。

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Force

删除当前 PowerShell 驱动器。

Type:SwitchParameter
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-LiteralName

指定驱动器的名称。

LiteralName 的值严格按照所键入的形式使用。 不会将任何字符解释为通配符。 如果名称包括转义符,请将其括在单引号 (') 中。 单引号指示 PowerShell 不要将任何字符解释为转义序列。

Type:String[]
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Name

指定要删除的驱动器的名称。 请不要在驱动器名称后面键入冒号 (:)。

Type:String[]
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:True

-PSProvider

指定 PSProvider 对象的数组。 此 cmdlet 删除并断开与指定 PowerShell 提供程序关联的所有驱动器。

Type:String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-Scope

指定驱动器的作用域。 此参数的可接受值为:Global、Local 和 Script,或相对于当前范围的数字。 范围数 0 到范围数。 当前范围编号为 0,其父级为 1。 有关详细信息,请参阅 about_Scopes

Type:String
Position:Named
Default value:Local
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-WhatIf

显示运行该 cmdlet 时会发生什么情况。 此 cmdlet 未运行。

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

输入

PSDriveInfo

可以通过管道将驱动器对象(例如 cmdlet 中的 Get-PSDrive 驱动器对象)传递给 Remove-PSDrive cmdlet。

输出

None

此 cmdlet 不返回任何输出。

备注

  • Remove-PSDrive cmdlet 旨在处理由任何 PowerShell 提供程序公开的数据。 若要列出会话中的提供程序,请使用 Get-PSProvider cmdlet。 有关详细信息,请参阅 about_Providers