Remove the drives mapped to an SMB share with New-SMBMapping. This can also remove drives mapped with New-PSDrive, NET USE or other tools. Requires PowerShell 5.0+.

      Remove-SmbMapping [[-LocalPath] String[]] [[-RemotePath] String[]] 
         [-CimSession CimSession[]] [-Force]
            [-PassThru] [-ThrottleLimit Int32] [-UpdateProfile]
               [-Confirm] [-WhatIf] [CommonParameters]

   -CimSession [CimSession[]]
       Run the cmdlet in a remote session or on a remote computer.
       Enter a computer name or a session object, such as the output of a New-CimSession or Get-CimSession cmdlet.
       The default is the current session on the local computer.
       Run the command without asking for user confirmation.
   -LocalPath [String[]]
       An array of the local paths associated with the SMB mappings to remove.
       Return an object representing the item with which you are working.
       By default, this cmdlet does not generate any output.
   -RemotePath [String[]]
       An array of the remote paths of the SMB shares associated with the mappings that this cmdlet removes.
   -ThrottleLimit [Int32]
       The maximum number of concurrent operations that can be established to run the cmdlet.
       If this parameter is omitted or a value of 0 is entered, then PowerShell will calculate an optimum throttle limit 
       for the cmdlet based on the number of CIM cmdlets that are running on the computer. The throttle limit applies 
       only to the current cmdlet, not to the session or to the computer.
       Remove the mapping persistently.
       If the drive mapping is currently persistent, it will no longer be re-established when the computer restarts.
       Prompt for confirmation before running the cmdlet.
       Show what would happen if the cmdlet was run. The cmdlet is not run.

If you remove a drive mapping for the current directory, the command will succeed but the directory will no longer be valid, so subsequent commands like get-childitem may fail.


Remove all SMB mappings:

PS C:\> Remove-SmbMapping

Remove the SMB mapping for X:

PS C:\> Remove-SmbMapping X: -force

“Joel: You look familiar. Have we met?
 Wilhelmina Slater: We're not even meeting now” ~ Ugly Betty, 2006 TV series

Related PowerShell Cmdlets

New-SmbMapping - Create a mapping to an SMB share.
Get-SmbMapping - Get Mapped SMB drives.
Get-SmbConnection - Retrieve the connections established from the SMB client to the SMB servers.
Script to remove drive mappings - Both PSDrives and SMB drive mappings Charlie Russel (
Windows cmd command: NET USE - Map drive.

Copyright © 1999-2024
Some rights reserved