Cmd Map Network Drive Better -
Windows' built-in command for mapping network drives is net use.
Syntax (concise):
net use [DriveLetter:] \\Server\Share [Password | *] [/user:[Domain\]Username] [/persistent:yes] [/savecred] [/delete]
Key switches:
Create map_drives.txt:
Z: \\server\share1
Y: \\server\share2
Batch script:
for /f "tokens=1,2" %%i in (map_drives.txt) do net use %%i %%j /persistent:yes
Mapping a network drive lets you assign a drive letter (like Z:) to a shared folder on another computer or NAS so you can access it like a local drive. In this post you'll learn how to map, disconnect, and troubleshoot network drives using the classic Windows Command Prompt (cmd.exe). I'll cover common options, practical examples, and tips for scripting and automation.
net use \\server\share
Access via \\server\share in Explorer without consuming a drive letter.
net use Z: \\server\share /persistent:yes
Once set, future mappings stay persistent until changed.
Mapping a network drive with the command line is not just a nostalgic alternative; it is a professional necessity for any repeatable, reliable, or remote administration task. The GUI is a learning tool; the command line is a production tool. By mastering net use for quick, persistent mappings and New-PSDrive for complex automation, you gain speed, precision, and auditability. The next time you need to connect to a shared folder, skip the right-click—open a terminal instead. Your future self, writing a login script at 2 AM, will thank you.
Mapping a network drive via the Command Prompt (cmd) is a powerful way to automate connections and manage files across a network. While many users rely on the File Explorer GUI, the net use command offers speed, precision, and the ability to script repetitive tasks. 🚀 The Core Command: net use
The primary tool for this task is the net use command. In its simplest form, it connects a local drive letter to a shared folder on a server. Basic Syntax net use [drive_letter]: \\[computer_name]\[share_name] Example:net use Z: \\Server01\Marketing Z: is the local drive letter you want to assign. \Server01 is the name or IP address of the remote computer. \Marketing is the specific shared folder. 🛠️ Advanced Options for Power Users
To make your network drives more reliable and secure, you should utilize these additional flags: 1. Persistent Connections
By default, a mapped drive may disappear after you reboot. To ensure the drive reconnects automatically every time you log in, use the /persistent switch.
Always Reconnect: net use Z: \\Server01\Share /persistent:yes Temporary Only: net use Z: \\Server01\Share /persistent:no 2. Using Specific Credentials
If the network share requires a different username and password than your current Windows login, use the /user switch.
Command: net use Z: \\Server01\Share [password] /user:[username]
Example: net use Z: \\Server01\Files P@ssword123 /user:WorkGroup\Admin
💡 Tip: If you omit the password in the command, Windows will securely prompt you to type it in. 3. Mapping Without a Drive Letter
You can connect to a share as a "network location" without taking up a drive letter (A-Z) by using an asterisk. Command: net use * \\Server01\Share 🧹 Managing and Deleting Drives
Keeping your workspace clean is just as important as setting it up. View Current Mappings
To see a list of every drive currently connected to your system: net use Delete a Specific Drive
If a drive is no longer needed or is showing a "Red X" error: net use Z: /delete Delete ALL Network Drives To wipe the slate clean and remove every mapped connection: net use * /delete ⚠️ Common Troubleshooting cmd map network drive better
System Error 67: The network name cannot be found. Double-check your spelling or ensure the server is online.
System Error 5: Access is denied. This usually means your credentials (username/password) are incorrect or lack permissions.
Drive Letter in Use: You cannot map to Z: if another device (like a USB or local partition) is already using that letter. 🤖 Automating with Batch Files
Mapping a network drive via Command Prompt (CMD) is often faster and more reliable for automation than using the File Explorer GUI. The primary tool for this is the CBT Nuggets Basic Command Syntax To map a drive, open CMD and use the following format: net use [DriveLetter]: \\[ServerName]\[SharedFolder] net use Z: \\OfficeServer\Marketing Pureinfotech Key Options for "Better" Mapping To make your mapping more robust, use these specific flags: Make it Permanent:
By default, mapped drives may disappear after a reboot. Use the /persistent:yes flag to ensure it reconnects automatically at login. net use Z: \\Server\Share /persistent:yes Automatic Letter Assignment:
If you don't care which drive letter is used, use an asterisk ( ) to let Windows pick the first available letter. net use * \\Server\Share Connect with Different Credentials:
If the network share requires a different username and password than your current Windows login, specify them in the command.
net use Z: \\Server\Share [Password] /user:[Domain]\[Username]
to be prompted for a password instead of typing it in plain text. Microsoft Learn Management & Troubleshooting List All Mapped Drives Disconnect a Specific Drive net use Z: /delete Disconnect All Drives net use * /delete Pro-Tips for Power Users
Mapping a network drive via Command Prompt (CMD) is often faster than clicking through menus, especially when you need to automate tasks or troubleshoot connections. While the standard net use command is well-known, doing it "better" involves mastering persistence, handling credentials securely, and knowing when to use modern alternatives like PowerShell. 1. Master the Standard net use Command
The foundation of mapping drives in CMD is the net use command. Use the following syntax for a standard, non-persistent connection:net use Z: \\ServerName\SharedFolder Better Ways to Use It:
Auto-Assign Drive Letters: Instead of manually picking a letter, use an asterisk (*) to let Windows assign the next available one. net use * \\ServerName\SharedFolder
Enable Persistence: To ensure the drive reappears after a reboot, add the /persistent:yes flag. net use Z: \\ServerName\SharedFolder /persistent:yes
Handle Spaces in Paths: Always wrap your UNC path in double quotes if it contains spaces. net use Z: "\\Server Name\Shared Folder" 2. Handling Credentials More Efficiently
By default, Windows uses your current login credentials. To connect as a different user "better," use these methods:
Manual Entry (Secure): Use an asterisk for the password to trigger a secure prompt rather than typing it in plain text. net use Z: \\ServerName\Share /user:Domain\Username *
Plain Text (Scripting only): Only use this in private scripts where security is less of a concern.
net use Z: \\ServerName\Share Password /user:Domain\Username 3. Cleaning Up and Troubleshooting
A "better" workflow includes clean disconnections to avoid "Ghost Drives" (drive letters that appear disconnected but are still "taken"). Guide: How to Map a Network Drive in Windows - NinjaOne
To "map a network drive better" using the Command Prompt (CMD), you can move beyond simple connections to creating persistent, secure, and reportable configurations. 1. Core Command: The Enhanced net use
The basic command is net use Z: \\Server\Share, but adding parameters makes it robust. Assigning a Drive Letter: net use Z: \\Server\Share . Windows' built-in command for mapping network drives is
Persistence: Use /persistent:yes to ensure the drive returns after a reboot .
Credentials: Add /user:Username Password if the network requires specific login details .
Automation: Use /savecred to store credentials so you aren't prompted every time. 2. Generate a "Status Report" of Mapped Drives
To see what is currently connected and where, use these reporting commands:
Quick List: Simply type net use and press Enter to see all active connections and their UNC paths .
Export to File: Run net use > C:\mapped_drives_report.txt to create a permanent text log of your network configuration .
Full Details: Use wmics path Win32_MappedLogicalDisk get DeviceID, ProviderName, SessionID for a more technical report including session IDs. 3. Advanced Management & Best Practices
The IT department at LogiCorp had a saying: "If you have to click more than three times, you’ve already failed."
Junior Sysadmin Kevin did not subscribe to this philosophy. Kevin loved the Graphical User Interface (GUI). He loved the soothing grey of File Explorer, the gentle curves of the "Map Network Drive" button, and the little dropdown menu that let him choose drive letters.
Senior Sysadmin Vance despised Kevin.
It was 4:55 PM on a Friday. The CFO needed a drive mapping pushed to fifty laptops immediately for a weekend audit.
Kevin sat at his station, cracking his knuckles. "Alright," he said, reaching for the mouse. "I’ll just Remote Desktop into each one, go to 'This PC,' hit 'Map Network Drive,' browse for the share..."
Vance stared at him. The silence in the room was heavy enough to crash a hard drive.
"Fifty machines," Vance said, his voice flat. "You’re going to click through fifty wizard dialog boxes? By the time you finish, it will be Tuesday."
"It’s the proper way," Kevin argued. "It’s the user-friendly way."
"User-friendly is for users," Vance snapped. "We are the architects of efficiency. Move."
Vance didn't sit down. He just leaned over Kevin’s keyboard, his fingers hovering like spiders over a web. He opened the command prompt with a snap of Win+R, typed cmd, and hit Enter. The black box flashed into existence, a void of infinite power.
"Watch and learn, Kevin."
Vance began to type. He didn't look at the keys. He typed with the rhythm of a machine gun.
net use Z: \\LogiCorp-Data\AuditFiles /persistent:yes
He hit Enter.
The command completed successfully.
"There," Vance said. "One down."
Kevin blinked. "But... you didn't check the 'Reconnect at sign-in' box."
Vance pointed at the screen. "/persistent:yes. That’s the box, Kevin. It’s just invisible. It’s pure logic."
"But what about credentials?" Kevin stammered. "What if they need a different user?"
Vance’s eyes glinted. He typed again.
net use Z: \\LogiCorp-Data\AuditFiles /user:LogiCorp\AuditAdmin MyP@ssw0rd123 /persistent:yes
Enter.
The command completed successfully.
"It’s faster, it’s scriptable, and it doesn't require me to navigate a labyrinth of Windows icons designed for people who don't know where the 'Any' key is," Vance said.
Kevin looked at his mouse. It looked slow. It looked like a toy.
"Now," Vance said, opening a text editor. "I am going to write a batch script with those fifty computer names, loop through them using psexec, and run this command on all of them simultaneously."
He typed furiously:
@echo off
for /f %%i in (computers.txt) do (
psexec \\%%i net use Z: \\LogiCorp-Data\AuditFiles /persistent:yes
)
"Kevin, hit enter."
Kevin hesitated, then pressed the key.
The screen scrolled. Text cascaded down the monitor like digital rain.
Z: deleted successfully. The command completed successfully. The command completed successfully. The command completed successfully.
Forty-five seconds later, it was done. The room was quiet.
Kevin looked at the stack of sticky notes on his desk where he wrote down drive letters. He looked at the command prompt. He realized he had spent years using a spoon to dig a swimming pool, while Vance had been using a backhoe.
"Go home, Kevin," Vance said, straightening his tie. "The weekend is yours. The cmd has provided."
Kevin walked out of the office, leaving his mouse unplugged. He knew that on Monday, he would be a different man. He would be a command line man.
Here’s a practical guide to mapping network drives using CMD more effectively—covering basic commands, advanced tips, and troubleshooting.
