Home » PowerShell » How to remove mapped network drive using PowerShell?

How to remove mapped network drive using PowerShell?

Using PowerShell and cmd in Windows Systems, you can remove mapped network drive.

PowerShell Remove-PSDrive cmdlet used to remove mapped network drive in PowerShell and net use in cmd used to remove mapped network drive.

In this article, I will explain you how to remove mapped network drive using PowerShell and cmd in Windows System.

Using PowerShell to remove mapped network drive

Use Remove-PSDrive cmdlet to remove mapped network drive using PowerShell.

Lets consider we have mapped network drive using New-PSDrive at drive letter K

 New-PSDrive -Name "K" -PSProvider "FileSystem" -Root "\\Corp-in-18\Software" -Persist 

Above command will create persistent mapped network drive for root specified path.

To remove, mapped network drive use below command

Remove-PSDrive K -Force -Verbose 

VERBOSE: Performing the operation "Remove Drive" on target "Name: K Provider: Microsoft.PowerShell.Core\FileSystem
Root: K:\".

Above command will remove mapped network drive with specified drive letter K.

To remove multiple drives, separate drives by comma (,) as given in below command.

Remove-PSDrive J,K -Force -Verbose 

VERBOSE: Performing the operation "Remove Drive" on target "Name: J Provider: Microsoft.PowerShell.Core\FileSystem
Root: J:\".

VERBOSE: Performing the operation "Remove Drive" on target "Name: K Provider: Microsoft.PowerShell.Core\FileSystem
Root: K:\".

You can get the mapped network drive using Get-PSDrive and using pipeline operator use Remove-PSDrive to remove specified drive letter.

Get-PSDrive J,K | Remove-PSDrive -Force -Verbose

VERBOSE: Performing the operation "Remove Drive" on target "Name: J Provider: Microsoft.PowerShell.Core\FileSystem
Root: J:\".

VERBOSE: Performing the operation "Remove Drive" on target "Name: K Provider: Microsoft.PowerShell.Core\FileSystem
Root: K:\".

Cool Tip: Do you know how to fix running PowerShell script disabled on System!

Using Cmd to remove mapped network drive

Using net use command to remove mapped network drive by specifying drive letter.

To remove a single network drive, use below command

C:\>net use K: /delete
K: was deleted successfully.

Cool Tip: Using multiline command in PowerShell!

Conclusion

I hope above article to remove mapped network drive using PowerShell and cmd useful. PowerShell Remove-PSDrive cmdlet and net use in cmd used to remove mapped network drive.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on ShellGeek home page.

Leave a Comment