Remove the drives mapped to an SMB share. Requires PowerShell 5.0+ and Windows 10.
Syntax Remove-SmbMapping [[-LocalPath] String] [[-RemotePath] String] [-CimSession CimSession] [-Force] [-PassThru] [-ThrottleLimit Int32] [-UpdateProfile] [-Confirm] [-WhatIf] [CommonParameters] Key -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. -Force Force the command to run without asking for user confirmation. -LocalPath [String] An array of the local paths associated with the SMB mappings to remove. -PassThru 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. -UpdateProfile Remove the mapping persistently. If the drive mapping is currently persistent, it will no longer be re-established when the computer restarts. -Confirm Prompt for confirmation before running the cmdlet. -WhatIf 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
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 (msmvps.com)
Windows cmd command: NET USE - Map drive.