Remove-PSDrive

Remove a temporary PowerShell drive mapped with New-PSDrive or remove a permanent drive mapping made with New-PSDrive, New-SMB-Mapping, NET USE or another tool.

Syntax
      Remove-PSDrive { [-name] string[] | [-literalName] string[] }
[-pSProvider string[]] [-scope string] [-force] [-Confirm] [-WhatIf] [-UseTransaction] [CommonParameters] Key -name string[] The PowerShell drive name(s) to remove, separate multiple names with commas. Do not type a colon (:) after the drive name. -literalName string[] The Drive name which will be used exactly as typed. No characters are interpreted as wildcards. If the name includes escape characters, enclose it in single quotation marks. -pSProvider Remove all of the drives associated with the specified PowerShell provider. e.g. FileSystem, Registry or Certificate. -scope An index that identifies the scope from which the drive is being removed. -force Override restrictions that prevent the command from succeeding, apart from security settings. e.g. -force will override a files read-only attribute, but will not change file permissions. -whatIf Describe what would happen if you executed the command without actually executing the command. -confirm Prompt for confirmation before executing the command. -UseTransaction Include the command in the active transaction.

Standard Aliases for Remove-PSDrive: rdr

If -force is used to remove the current drive, you may see the error "Cannot find drive, a drive with the name n does not exist" immediately after the drive is removed.

If you create a Drive Mapping and set it as current, then remove the drive with -force and re-create it, pointing to a different location, the new files will not be visible until you Set-Location to the drive (even though the current location appears to be correct).

Examples

Remove a PowerShell drive named S:

PS C:\> Remove-PSDrive -name s

Disconnect the X: and S: mapped network drives:

PS C:\> Get-PSDrive X, S | Remove-PSDrive

“Peace is not the absence of war; it is a virtue; a state of mind; a disposition for benevolence, confidence, and justice” ~ Baruch Spinoza.

Related PowerShell Cmdlets

Get-PSDrive - Get drive information (DriveInfo).
New-PSDrive - Install a new drive on the machine.
Remove-SmbMapping - Remove an SMB mapping.
Get-Command - Retrieve basic information about a command.
Get-Member - Enumerate the properties of an object.
Get-Help - Open the help file.
Equivalent bash command: umount(8) - detach/unmount a device.


 
Copyright © 1999-2024 SS64.com
Some rights reserved