Map Network Drives with PowerShell in Windows 11
Mapping a network drive with PowerShell in Windows 11 connects you to a shared folder on another computer using text commands instead of File Explorer . It is quick to repeat, and you can reuse the same commands later in a script.
PowerShell is a built-in command-line tool for running commands and automating everyday tasks. To map a drive, you run the New-PSDrive command. It needs only two things: a free drive letter such as Z: and the network path to the share.
Use the New-SmbMapping cmdlet in PowerShell to map network drives persistently. Open PowerShell, then run New-SmbMapping -LocalPath “Z:” -RemotePath “\ServerNameShare” -Persistent $true, replacing “Z:” and the server path with your desired drive letter and network share.
Map or unmap network drive in PowerShell
You can map shared folders directly from PowerShell without opening File Explorer . The cmdlet is New-PSDrive, followed by your preferred drive letter and the network path.
File Explorer is the standard tool for managing network drives, but PowerShell can map and unmap the same connections. The steps below show how.
- Open the Start menu and type PowerShell.
- Under Best match, select the PowerShell app. A Windows Terminal window opens with a PowerShell prompt.
An elevated session and a normal session keep separate lists of mapped drives. A drive mapped from an administrator window will not show up in File Explorer , which runs as your normal user. If you already did this, close the window, open PowerShell normally and map the drive again.
- Type the command format shown below into the terminal window:
New-PSDrive -Name "DriveLetter" -PSProvider "FileSystem" -Root "\\ServerName-or-IPAddress\SharedFolder" -Persist
Replace `DriveLetter` with the letter you want to use. Pick one that is not already taken by a local disk, DVD drive or another mapped drive. Change `ServerName` and `SharedFolder` to the actual computer name and shared folder name.
Example:
New-PSDrive -Name "Z" -PSProvider "FileSystem" -Root "\\HomePC\Documents" -Persist
- Press Enter to run the command.
- If prompted, enter the username and password for the share. Once they are accepted, the connection is made and the network share is mapped.
Protected shares always ask for credentials. To avoid retyping them each time you run the command, store them in a variable first and pass that variable along with the mapping command. The steps below do this.
- Run the command below to store the account credentials in a variable.
$cred = Get-Credential -Credential USERNAME
Replace USERNAME with the actual account name. For a share on another PC, use the account that exists on that PC.
- When the credentials window appears, enter the password and click OK. It should look similar to the example below.

- Run the command below. It maps the network drive and passes the stored credentials in the same command.
New-PSDrive -Name "E" -Root "\\HomePC\Documents" -Persist -PSProvider "FileSystem" -Credential $cred
The variable only lasts as long as the current PowerShell window. If you close the window, run the first command again to re-enter the password.
Windows Credential Manager is a secure vault in Windows for storing passwords. It gives you another way to save login details. Run the following command: cmdkey /generic:SERVERNAME /user:USERNAME /pass:PASSWORD. Replace `USERNAME` with the account name and `SERVERNAME` with the name of the host computer.
cmdkey /add:HomePC /user:WORKGROUP\username /pass:password
With the credentials saved in Credential Manager, you can run the mapping command without giving user details, and no prompt window appears. To remove a saved entry later, open Control Panel User Accounts Credential Manager Windows Credentials, select the entry and choose Remove.
New-PSDrive -Name "P" -Root "\\HomePC\Documents" -Persist -PSProvider "FileSystem"
Unmap or disconnect shared network drives using PowerShell
When you no longer need access to a shared folder, you can disconnect the drive from PowerShell. First check your active connections with Get-PSDrive. Then use Remove-PSDrive with the drive letter. No restart is needed. To get the drive back, map it again.
- Run the command below to view active connections. The list also includes local disks and other PowerShell drives, so look for the letter you assigned to the network share.
Get-PSDrive -PSProvider "FileSystem"
- Once you know the letter, run the command below to disconnect that drive.
Remove-PSDrive -Name DriveLetter
Replace `DriveLetter` with the letter assigned to the drive you want to remove. For example:
Remove-PSDrive -Name Z
You can also disconnect several drives in one command, using this syntax:
Get-PSDrive X, W | Remove-PSDrive
That completes the process. Here is a quick summary:
- Mapping and unmapping shared network drives with PowerShell in Windows 11 is a quick way to manage access to network resources.
- Follow the steps above to map a drive and open the shared folder. Run PowerShell as a normal user so the drive appears in File Explorer.
- You can include credentials in the PowerShell command or store them in Credential Manager. The first avoids retyping within a session, and the second saves them for later sessions.
- PowerShell can also list and disconnect mapped drives, so you can manage every network connection from one place.
Have a question about this guide?
Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.
Did this guide fix your problem?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
No comments yet — be the first to share your thoughts!