Map Drive From Command Line -
For decades, the average Windows user has mapped network drives the same way: open File Explorer, right-click "This PC," select "Map network drive," pick a letter, type a path, and click "Finish." It’s visual, intuitive, and serviceable for the occasional connection.
New-PSDrive -Name "Z" -PSProvider FileSystem -Root "\\server\share" -Persist This creates a drive visible in File Explorer and across all applications—identical to net use Z: \\server\share . PowerShell handles credentials more securely using PSCredential objects: map drive from command line
net use Z: /delete To delete all mapped drives at once (common in logoff scripts): For decades, the average Windows user has mapped
But for IT professionals, power users, and automation enthusiasts, the graphical approach is a bottleneck. It’s slow, inconsistent across remote sessions, and impossible to script. The command line—specifically net use and, more recently, PowerShell’s New-PSDrive —offers speed, precision, and repeatability. The net use command is a relic of
This feature dives deep into the art and science of mapping drives from the command line, from basic syntax to advanced scripting techniques. The net use command is a relic of the MS-DOS and OS/2 era, yet it remains one of the most reliable networking tools in modern Windows. It connects, disconnects, and displays information about shared resources. Basic Mapping Syntax The simplest form is almost poetic in its brevity:
net use Z: \\server\share /user:DOMAIN\username * The asterisk ( * ) tells Windows to prompt for a password without echoing it to the screen. For fully automated scripts (use with caution), you can include the password directly:
| Task | Command | |------|---------| | Map persistent drive | net use Z: \\server\share /persistent:yes | | Map with specific credentials | net use Z: \\server\share /user:DOMAIN\user * | | Delete mapping | net use Z: /delete | | Delete all mappings | net use * /delete | | PowerShell persistent drive | New-PSDrive -Name Z -PSProvider FileSystem -Root \\server\share -Persist | | View all connections | net use |