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.
Affects: Windows 11 (and Windows 10) with network shares.
Fix time: ~3 minutes.
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.
- Open Terminal (Admin if you need persistence across reboots for all users; non-admin otherwise).
- Map a share:
net use Z: \\Server\Share /user:DOMAIN\username passwordReplace Z: with available letter, \\Server\Share with the UNC path, DOMAIN\username with credentials. For workgroup: use server name as “domain.”
- For persistent connection (auto-reconnect on logon):
net use Z: \\Server\Share /user:DOMAIN\username password /persistent:yes - 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.
- List active mappings:
net useShows drive letter, UNC path, status.
- Remove a mapping:
net use Z: /delete - Remove all:
net use * /delete /yes
net use is the classic syntax; works on every Windows since NT.
Method 2: PowerShell New-PSDrive for richer control
For PowerShell-native scripts.
- From Terminal (PowerShell):
$cred = Get-Credential New-PSDrive -Name Z -PSProvider FileSystem -Root "\\Server\Share" -Credential $cred -PersistThe
Get-Credentialprompts for username/password securely. - 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 - List PSDrives:
Get-PSDrive -PSProvider FileSystem. - Remove:
Remove-PSDrive -Name Z. - 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.
- Open Group Policy Management Console on a domain controller (or Local Group Policy Editor for single PC).
- Navigate to User Configuration → Preferences → Windows Settings → Drive Maps.
- Right-click → New → Mapped Drive.
- Configure:
- Action: Create / Replace / Update.
- Location: \\Server\Share
- Drive Letter: Z (or pick).
- Reconnect: tick.
- Run in logged-on user’s security context: tick.
- Click OK. Apply the GPO to the OU containing target users.
- For one-time logon script: place a batch file with
net usecommands in User Configuration → Policies → Windows Settings → Scripts → Logon. - Test: run
gpresult /h C:\result.htmlon 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.