How to Map a Network Drive From the Command Line on Windows 11
🔍 WiseChecker

How to Map a Network Drive From the Command Line on Windows 11

Quick fix: From Terminal, run net use Z: \\Server\Share /user:DOMAIN\username password /persistent:yes. Replace Z: with desired letter, server path, credentials. The /persistent:yes flag reconnects on next login. To list current maps: net use. To remove: net use Z: /delete.

You want to mount a network share as a drive letter programmatically — for scripts, logon scripts, or repeated setup. The Settings UI is fine for one-off, but command-line is faster, scriptable, and shows clearly what credentials are being used.

Symptom: Need to map a network share (SMB) to a drive letter via command line on Windows 11.
Affects: Windows 11 (and Windows 10) with network shares.
Fix time: ~3 minutes.

ADVERTISEMENT

What causes this

Windows’s net use command maps SMB network shares to drive letters. PowerShell’s New-PSDrive is the modern equivalent with more options. Both create a mount accessible at the drive letter via File Explorer or any app expecting a local-like path.

Method 1: net use for simple SMB mapping

The traditional command.

  1. Open Terminal (Admin if you need persistence across reboots for all users; non-admin otherwise).
  2. Map a share:
    net use Z: \\Server\Share /user:DOMAIN\username password

    Replace Z: with available letter, \\Server\Share with the UNC path, DOMAIN\username with credentials. For workgroup: use server name as “domain.”

  3. For persistent connection (auto-reconnect on logon):
    net use Z: \\Server\Share /user:DOMAIN\username password /persistent:yes
  4. For interactive password prompt (more secure than typing in command):
    net use Z: \\Server\Share /user:DOMAIN\username *

    The * makes net use prompt for password.

  5. List active mappings:
    net use

    Shows drive letter, UNC path, status.

  6. Remove a mapping:
    net use Z: /delete
  7. Remove all:
    net use * /delete /yes

net use is the classic syntax; works on every Windows since NT.

ADVERTISEMENT

Method 2: PowerShell New-PSDrive for richer control

For PowerShell-native scripts.

  1. From Terminal (PowerShell):
    $cred = Get-Credential
    New-PSDrive -Name Z -PSProvider FileSystem -Root "\\Server\Share" -Credential $cred -Persist

    The Get-Credential prompts for username/password securely.

  2. For non-interactive: store credentials in a script with encryption:
    $securePassword = ConvertTo-SecureString "password" -AsPlainText -Force
    $cred = New-Object System.Management.Automation.PSCredential ("DOMAIN\username", $securePassword)
    New-PSDrive -Name Z -PSProvider FileSystem -Root "\\Server\Share" -Credential $cred -Persist
  3. List PSDrives: Get-PSDrive -PSProvider FileSystem.
  4. Remove: Remove-PSDrive -Name Z.
  5. For scheduled mapping at logon: save the PowerShell script as map-drives.ps1. Add a Scheduled Task triggered at logon to run it.

PowerShell is more flexible. Use for scripts and modern automation.

Method 3: Group Policy for organization-wide drive mapping

For IT administrators.

  1. Open Group Policy Management Console on a domain controller (or Local Group Policy Editor for single PC).
  2. Navigate to User Configuration → Preferences → Windows Settings → Drive Maps.
  3. Right-click → New → Mapped Drive.
  4. Configure:
    • Action: Create / Replace / Update.
    • Location: \\Server\Share
    • Drive Letter: Z (or pick).
    • Reconnect: tick.
    • Run in logged-on user’s security context: tick.
  5. Click OK. Apply the GPO to the OU containing target users.
  6. For one-time logon script: place a batch file with net use commands in User Configuration → Policies → Windows Settings → Scripts → Logon.
  7. Test: run gpresult /h C:\result.html on a target PC. The Drive Maps section confirms what’s applied.

This is the right path for managing drive maps across many PCs in a domain.

How to verify the fix worked

  • Run net use. The new mapping appears in the list as “OK.”
  • Open File Explorer. The mapped drive appears under This PC with its letter.
  • Navigate to the drive. Files in the network share are accessible.
  • For persistent maps: sign out and back in. Drive re-mounts automatically.

If none of these work

If mapping fails with errors: 0x80070043 (Network path not found): server name doesn’t resolve. Try IP instead: net use Z: \\192.168.1.10\Share .... 0x80070005 (Access denied): credentials are wrong, or user doesn’t have share permissions. Verify by accessing share via File Explorer first. 0x800704CF (Network location cannot be reached): SMB version mismatch. Modern Windows defaults to SMB 3.x; older NAS may need SMB 2 or SMB 1. Enable older SMB: Enable-WindowsOptionalFeature -Online -FeatureName SMB1Protocol (security risk; only as last resort). For credentials caching: cmdkey /add:Server /user:DOMAIN\username /pass:password. Stores credentials so future net use doesn’t need them. For shares behind firewall: SMB uses TCP port 445. Verify firewall allows. Test with Test-NetConnection -ComputerName Server -Port 445.

Bottom line: net use Z: \\Server\Share /user:DOMAIN\user pass /persistent:yes. PowerShell’s New-PSDrive -Persist for modern scripts. Group Policy Preferences for organization-wide deployment.

ADVERTISEMENT