PowerTip: Use PowerShell to Remove Mapping to Share

Summary: Use Windows PowerShell to remove mapping to a SMB file share.

Hey, Scripting Guy! Question How can I use Windows PowerShell in Windows 8.1 to remove mapping to an SMB file share?

Hey, Scripting Guy! Answer Use the Remove-SMBMapping cmdlet, specify either the local path or the remote path,
          and use the –Force parameter to suppress prompts:

Remove-SmbMapping -LocalPath j: -Force

Comments (2)

  1. Awesome Tip! More so of the SMB commands than the Remove-SMBMapping cmdlet… I have been struggling to find a way to consistently map drives between AD forests with a specified user account in a script. This solve my PSDrive problems, my Net Use problems, etc.

    My only issue is that once the script finishes, I do a check to verify the drive is still available, I wait 5 seconds, then do the following:
    Remove-SmbMapping -LocalPath $DestinationLetter -Force

    Unfortunately, it says that the Status of the drive is Unavailable. Luckily I only need to consistently use 5 drives, and you get 26 letters!

    Thanks again!

  2. moi says:

    Just do :

    net use /delete

Skip to main content