Net Use Delete Mapped Drive: Complete Command Line Guide

Learn how to delete mapped drives using net use command line. Step-by-step guide for CMD, PowerShell, force deletion, and troubleshooting common errors.

Is your Windows PC cluttered with old mapped drives that won't go away? You know the ones—they show up in File Explorer with that little red X, or they reconnect every time you boot up even though the network share they point to was decommissioned months ago. The net use delete mapped drive command is the fastest way to clean them up, and in this guide, you'll master it in minutes.

I've spent the better part of fifteen years managing Windows networks, and I can tell you this: the command prompt is still the most reliable tool for managing mapped drive connections. File Explorer works fine for the simple stuff, but when you need precision, speed, or automation, the command line wins every time.

This guide covers the basic syntax, advanced scenarios like force deletion, and troubleshooting for the most common errors. By the end, you'll be able to clean up any mapped drive situation Windows throws at you.


Detailed close-up of a computer keyboard featuring the Windows key in focus.

Understanding the Net Use Command Syntax

Before we start deleting things, let's make sure we're speaking the same language.

What is a Mapped Drive?

A mapped drive is essentially a shortcut. You assign a drive letter—say, Z:—to a network share located somewhere else on your network. That share might live on a file server, a NAS device, or even another PC. The technical term for the network location is a UNC path (Universal Naming Convention), which looks something like \\ServerName\SharedFolder.

Z: --> \\ServerName\SharedFolder

That's the whole concept. A letter pointing to a remote location.

Mappings become stale for all sorts of reasons. The server gets renamed, the share gets moved, or the credentials you used to connect are no longer valid. Sometimes the mapping is simply a leftover from an old project or a previous job role. Whatever the reason, these dead connections clutter your File Explorer and can slow down your login process.

The command line gives you more control than File Explorer ever will. You can target specific drives, delete everything at once, and even automate the whole process with scripts.

Net Use Command Parameters Explained

The net use command is the Swiss Army knife for network connections in Windows. Here's the syntax you'll need for deletion:

net use [driveLetter:] /delete [/y]

Let me break that down:

ParameterFunction
net useThe command itself—manages network connections
[driveLetter:]The specific drive to remove (e.g., Z:)
/deleteTells Windows to remove the mapping
/ySkips the confirmation prompt—essential for scripts
The /y parameter is your friend. Without it, Windows will ask "Do you want to continue?" every single time. That's fine for one-off deletions, but it's a script-killer in batch files.

Here's a trick many people don't know: you can use the wildcard * to target all mappings at once:

net use * /delete /y

This nukes every mapped drive on the system. Useful for login scripts where you want a clean slate before remapping drives.


Close-up of a RGB lit keyboard with a screen displaying 'Data Transfer Complete'.

How to Delete a Mapped Drive Using CMD

Let's get practical. Here's exactly how to delete mapped drives using the command line.

Delete a Single Mapped Drive

Step 1: Open Command Prompt. For most cases, you don't need administrator rights—just press Win + R, type cmd, and hit Enter. If you're getting access denied errors, right-click Command Prompt and select "Run as administrator."

Step 2: Type the following command, replacing Z: with your actual drive letter:

net use Z: /delete

Step 3: Press Enter. You should see:

Z: was deleted successfully.

That's it. The drive disappears from File Explorer immediately.

Let me verify it's gone:

net use

This lists all current mappings. If the drive is gone, you'll see "There are no entries in the list" or just the remaining mappings.

One thing I've learned the hard way: always double-check which drive letter you're targeting. I once deleted the wrong mapping because I was in a hurry and didn't verify the letter. It wasn't catastrophic—I just remapped it—but it was an unnecessary headache.

Delete All Mapped Drives at Once

When you need to clear everything, the wildcard approach is your best bet:

net use * /delete /y

The * tells Windows to match all drive letters. The /y suppresses the confirmation prompt that would otherwise appear for each mapping.

This command is particularly useful in login scripts. I've set up countless batch files that start with this line to ensure users get a fresh set of mappings every time they log in. It prevents the "duplicate drive letter" errors that happen when mappings persist across sessions.

Here's what a typical login script looks like:

@echo off
net use * /delete /y
net use Z: \\Server01\Shared /persistent:yes
net use M: \\Server02\Marketing /persistent:yes

The first line clears everything, then the script remaps only what's needed.


Force Delete Mapped Drive That Won't Disconnect

Sometimes the simple commands just don't work. You run net use Z: /delete and get an error instead of success. Let's talk about why that happens and how to force your way through.

Why Does Net Use Delete Fail?

In my experience, there are three main culprits:

  1. The drive is in use. If any program has files open on that drive, Windows will refuse to disconnect it. This is the most common cause.

  2. Permission issues. You might not have the rights to remove the mapping, especially if it was created under a different user account or with elevated privileges.

  3. Stale connections. The mapping points to a server that's no longer reachable, and Windows is stuck waiting for a response that never comes.

Here are the error messages you're likely to see:

ErrorMeaning
"Access is denied"You lack the necessary permissions
"Error 5"Same as above—access denied
"The network connection could not be found"The mapping is stale or already gone
"The local device name is already in use"Drive letter conflict

Force Deletion with /y and Other Workarounds

First, try the force approach:

net use Z: /delete /y

The /y flag doesn't just skip the confirmation—it also tells Windows to close any open handles and force the disconnection. In many cases, this is all you need.

If that fails, you have a few more options.

Registry cleanup. This is the nuclear option, and I want to be clear: editing the registry is risky. Always back up your registry before making changes. Navigate to:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2

You'll see folders named like ##ServerName#ShareName. Right-click the one you want to remove and delete it. This removes the mapping at the system level, bypassing the normal deletion process.

PowerShell alternative. If you're on Windows 10 or 11, PowerShell offers a more robust approach:

Remove-SmbMapping -LocalDrive Z -Force

The -Force parameter does what you'd expect—it forces the removal even if the connection is in use.


PowerShell vs CMD: Which Is Better for Removing Mapped Drives?

This is a question I get asked a lot, and the honest answer is: it depends on what you're doing.

Using Remove-SmbMapping in PowerShell

PowerShell's Remove-SmbMapping cmdlet is the modern alternative to net use. Here's the basic syntax:

Remove-SmbMapping -LocalDrive Z

And to remove all mappings:

Get-SmbMapping | Remove-SmbMapping -Force

PowerShell shines when you need to handle errors gracefully. You can wrap commands in try/catch blocks, check if a mapping exists before deleting it, and integrate with other PowerShell modules.

Here's a quick comparison:

TaskCMD (net use)PowerShell (Remove-SmbMapping)
Delete one drivenet use Z: /deleteRemove-SmbMapping -LocalDrive Z
Delete all drivesnet use * /delete /yGet-SmbMapping | Remove-SmbMapping -Force
Skip confirmation/y flag-Force parameter
Check if drive existsnet useGet-SmbMapping

When to Stick with Net Use

For quick, one-off tasks, net use is hard to beat. It's simpler, faster to type, and works in any batch file without extra setup. If you're writing a login script for a small office, net use is perfectly adequate.

PowerShell makes more sense when you're building complex automation. If you need to conditionally delete drives based on user groups, log the results, or handle errors programmatically, PowerShell's scripting capabilities give you the tools to do it properly.

My recommendation? Learn both. Use net use for quick fixes and simple scripts. Use PowerShell when you need more control or when you're already working in a PowerShell environment.


Troubleshooting Common Net Use Delete Errors

Let's walk through the most common errors and how to fix them.

Error 5: Access Denied

This one's frustrating because the fix isn't always obvious. The most common cause is that you're not running Command Prompt with administrator privileges.

Solution: Right-click Command Prompt and select "Run as administrator." Then try the deletion again.

If that doesn't work, the mapping might have been created under a different user account. This happens when you've used runas or when a service created the mapping. In that case, you'll need to log in as that user or use an elevated prompt.

Error 85: Local Device Name Already in Use

This error means the drive letter you're trying to use is already assigned to another mapping. It's a conflict issue.

Solution: First, list all current mappings to see what's using the letter:

net use

You'll see output like this:

Status       Local     Remote                    Network
-------------------------------------------------------------------------------
OK           Z:        \\Server01\Shared         Microsoft Windows Network
OK           Y:        \\Server02\Marketing      Microsoft Windows Network

If you see a mapping you don't recognize, delete it first, then try again. Or simply use a different drive letter for your new mapping.

How to Clear Mapped Drive Cache

Windows maintains a cache of network connections to speed up reconnection. Sometimes this cache gets corrupted, causing phantom drives that won't go away.

To clear the cache:

  1. Open Registry Editor (regedit)
  2. Navigate to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2
  3. Delete the entries you want to clear
  4. Restart Explorer (right-click the taskbar, select Task Manager, find Windows Explorer, right-click, and select Restart)

This usually resolves persistent phantom drives. If you're still having issues, a full system restart is the next step.


Batch Script to Delete Mapped Drives Automatically

Automation is where the command line really shines. Let me show you how to build scripts that handle drive cleanup for you.

Creating a Simple Batch File

Here's a basic batch file that clears all mappings and remaps what's needed:

@echo off
REM ============================================
REM Network Drive Cleanup Script
REM Clears all mappings and remaps required drives
REM ============================================

echo Clearing all network drive mappings...
net use * /delete /y

if %errorlevel% neq 0 (
    echo Warning: Some mappings could not be deleted.
) else (
    echo All mappings cleared successfully.
)

echo.
echo Mapping network drives...
net use Z: \\Server01\Shared /persistent:yes
net use M: \\Server02\Marketing /persistent:yes

echo.
echo Done. Current mappings:
net use

pause

The %errorlevel% check lets you handle failures gracefully. If the deletion fails, the script warns you instead of silently continuing.

To schedule this script, use Task Scheduler:

  1. Open Task Scheduler
  2. Click "Create Basic Task"
  3. Set the trigger (e.g., "At log on")
  4. Set the action to "Start a program"
  5. Browse to your .bat file
  6. Finish

Advanced Scripting with PowerShell

PowerShell gives you more control. Here's a script that deletes specific drives while skipping any that are in use:


$drivesToDelete = @("Z:", "Y:", "M:")

foreach ($drive in $drivesToDelete) {
    try {
        Remove-SmbMapping -LocalDrive $drive -Force -ErrorAction Stop
        Write-Host "Deleted $drive" -ForegroundColor Green
    }
    catch {
        Write-Host "Could not delete $drive : $($_.Exception.Message)" -ForegroundColor Yellow
    }
}

Write-Host "`nRemaining mappings:"
Get-SmbMapping | Format-Table -AutoSize

This script handles errors gracefully, telling you which drives were deleted and which weren't, along with the reason.


FAQ

How do I delete a mapped drive that no longer exists?

If the server is gone or unreachable, net use /delete might fail. Try net use * /delete /y to clear everything at once. If that doesn't work, you may need to clear the registry key at HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2.

Why does 'net use * /delete' wait for confirmation?

Without the /y flag, Windows asks for confirmation before deleting each mapping. Add /y to skip the prompt: net use * /delete /y. This is essential for scripts.

Can I delete a mapped drive without admin rights?

Yes, if the drive was mapped by your current user account. If it was created by another user or with elevated privileges, you'll need admin rights. Check by running net use and seeing if the mapping appears in your session.

How to remove mapped network drive in Mac?

On macOS, use the umount command in Terminal:

umount /Volumes/DriveName

Or use Finder: right-click the drive in the sidebar and select "Eject." The process is different from Windows, but the concept is the same.


Wrapping Up

You've now got the complete toolkit for deleting mapped drives via the command line. Let me recap the key methods:

  • Single drive: net use Z: /delete
  • All drives: net use * /delete /y
  • Force deletion: Add /y or use Remove-SmbMapping -Force in PowerShell
  • Automation: Batch files or PowerShell scripts scheduled with Task Scheduler

The /y flag is your best friend for automation—don't forget it.

I've used these commands hundreds of times across different Windows versions, and they've never let me down. The key is knowing which tool fits the situation. For quick fixes, net use is all you need. For complex scenarios, PowerShell gives you the flexibility to handle edge cases gracefully.

Have a stubborn mapped drive that won't go away? Try the force delete method above, and if you still face issues, drop a comment below—we'll help you fix it!

Back