How to Map Network Drives with PowerShell in Windows 11
This guide explains how to map or disconnect network drives using PowerShell in Windows 11. Windows PowerShell is a tool that helps you automate tasks on your computer. It includes a command-line shell and a scripting language. The app comes built-in with Windows.
Why Use PowerShell to Map Network Drives?
Why map network drives with PowerShell? It is faster than clicking through menus and allows you to automate connections for many computers at once. What happens when done? You gain a persistent network location that acts like a local folder, making file access seamless.
New-PSDrive vs New-SmbMapping
It is important to know the difference. New-PSDrive creates a session-specific drive that often does not appear in File Explorer. For persistent mapped drives that show up in Windows, use New-SmbMapping. You can find more details in the official Microsoft documentation.
UAC and Administrative Context
Windows uses User Account Control (UAC) to separate standard and admin tasks. If you run PowerShell as an administrator, your mapped drives will not be visible to your standard user account. To fix this, you can enable linked connections. (Requires Admin Privileges)
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLinkedConnections -Value 1 -PropertyType DWord -Force
How to Map a Network Drive Silently
To map a drive without pop-ups, use the -SkipCredentialCheck or pre-stored credentials. You can also use Test-NetConnection to verify the server is reachable before mapping. This prevents errors during silent execution.
if (Test-NetConnection -ComputerName "ServerName" -Port 445) { New-SmbMapping -LocalPath "Z:" -RemotePath "\\ServerName\Share" -Persistent $true }Step 1: Open PowerShell
Click on the Start Menu and search for PowerShell. Select and open the app. Note: Do not run as administrator unless you need to change system settings.
Step 2: Map the Drive
Use the New-SmbMapping command for a persistent network location that shows in File Explorer.
New-SmbMapping -LocalPath "Z:" -RemotePath "\\ServerName\Share" -Persistent $true
Step 3: Check Existing Connections
To see your current network drives, use the following command:
Get-SmbMapping
Unmap or Disconnect Network Drives
To remove a specific drive, use the Remove-SmbMapping command.
Remove-SmbMapping -LocalPath "Z:" -Force
Summary
Why use PowerShell? It provides a powerful way to manage network shares and automate drive assignments. What happens when you map a drive? You create a persistent link to a remote folder, allowing you to access files as if they were on your local machine. What happens when you unmap a drive? The connection is terminated, and the drive letter is removed from your system.
Why does my PowerShell mapped drive not appear in File Explorer?
If you use New-PSDrive, the mapping is often restricted to the current PowerShell session. Furthermore, if you run PowerShell as an administrator, the drive is created in a different security context than your user account. Use New-SmbMapping in a standard user window to ensure the drive appears in File Explorer.
Was this guide helpful?
Leave a Reply