- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to remove the mapped network drive using PowerShell?
To remove mapped drives from PowerShell on windows systems, you can use both PowerShell and cmd commands.
Using the cmd command
You can use the below command for a single mapped drive-by specifying the disk drive letter or by using the wildcard character (*).
To remove a single mapped drive.
Example
net use K: /delete
Output
PS C:\WINDOWS\system32> net use K: /delete K: was deleted successfully.
To remove multiple mapped drives together.
Example
net use * /delete
You need to confirm removing multiple mapped disks together.
Output
PS C:\WINDOWS\system32> net use * /delete You have these remote connections: K: \remoteshare\shared M: \remoteshare\shared folder Continuing will cancel the connections. Do you want to continue this operation? (Y/N) [N]: Y The command completed successfully.
Using the PowerShell method
To remove the mapped network drive with PowerShell command, you need to provide the drive letter in the cmdlet. If you want to remove the multiple drives together then separate them by comma (,).
Remove-PSDrive K,M –Force -Verbose PS C:\WINDOWS\system32> Remove-PSDrive K,M -Force -Verbose VERBOSE: Performing the operation "Remove Drive" on target "Name: K Provider: Microsoft.PowerShell.Core\FileSystem Root: K:\". VERBOSE: Performing the operation "Remove Drive" on target "Name: M Provider: Microsoft.PowerShell.Core\FileSystem Root: M:\".
Alternatively, you can get the mapped drive using Get-PSDrive and pipeline Remove-PSDrive command to remove them.
Get-PSDrive K,M | Remove-PSDrive -Force -Verbose
Output
PS C:\WINDOWS\system32> Get-PSDrive K,M | Remove-PSDrive -Force -Verbose VERBOSE: Performing the operation "Remove Drive" on target "Name: K Provider: Microsoft.PowerShell.Core\FileSystem Root: K:\". VERBOSE: Performing the operation "Remove Drive" on target "Name: M Provider: Microsoft.PowerShell.Core\FileSystem Root: M:\".
Advertisements