Skip to content
Follow
Windows

Map Network Drives with PowerShell in Windows 11

Richard
Written by
Richard
Jul 25, 2023 Updated Aug 13, 2026 3 min read
How to Lock and Unlock OneDrive Personal Vault in Windows 11
How to Lock and Unlock OneDrive Personal Vault in Windows 11

Mapping network drives with PowerShell in Windows 11 lets you connect to shared folders on other computers using quick text commands instead of clicking through File Explorer . PowerShell is a built-in Windows command-line tool that runs specific commands to speed up everyday tasks.

Running the New-PSDrive command connects your PC to a shared folder instantly. You just need a drive letter, like Z:, and the network path, such as \\Server\Share, to finish the setup.

⚡ Quick Answer

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

Multiple methods exist for mapping or unmapping (disconnecting) network drives in Windows.

File Explorer serves as the standard tool for managing network drives. However, the PowerShell app also maps and unmaps these connections.

The steps below outline how to perform this process.

Open the Start Menu , search for PowerShell, and select the application under Best match to launch the Windows Terminal prompt.

📝Important
Avoid running PowerShell as an administrator. Doing so prevents the mapped drive from appearing in File Explorer.

Type the command format shown below into the terminal window:

💻Code
New-PSDrive -Name "DriveLetter" -PSProvider "FileSystem" -Root "\\ServerName-or-IPAddress\SharedFolder" -Persist

Replace `DriveLetter` with the desired letter. Change `ServerName` and `SharedFolder` to reflect the actual computer name and shared folder name.

Example:

💻Code
New-PSDrive -Name "Z" -PSProvider "FileSystem" -Root "\\HomePC\Documents" -Persist

Entering a username and password completes the connection when prompted, finishing the network share mapping.

Protected shares always trigger a credentials prompt. Storing authentication details inside a variable avoids repetitive typing during command execution.

Executing the following steps incorporates the username and password directly into the command structure.

Run the command below first to store account credentials inside a variable.

PowerShell
$cred = Get-Credential -Credential USERNAME

Replace USERNAME with the actual account name.

A prompt window similar to the example below appears on screen. Enter the password and click Ok to save those credentials.

Windows 11 use PowerShell to map network drives
Windows 11 use PowerShell to map network drives

Stored credentials allow executing the command below to map the network drive while passing authentication details simultaneously.

💻Code
New-PSDrive -Name "E" -Root "\\HomePC\Documents" -Persist -PSProvider "FileSystem" -Credential $cred

Saving login details inside Windows Credential Manager (a secure Windows vault for storing passwords) provides an alternative approach. Run the following command: cmdkey /generic:USERNAME /add:SERVERNAME. Replace `USERNAME` with the account name and `SERVERNAME` with the host computer name.

💻Code
cmdkey /add:HomePC /user:WORKGROUND\username /pass:password

Credentials stored inside the Credential Manager permit running PowerShell commands without specifying user details or encountering prompt windows.

💻Code
New-PSDrive -Name "P" -Root "\\HomePC\Documents" -Persist -PSProvider "FileSystem"

Unmap or disconnect shared network drives using PowerShell

PowerShell manages the unmapping or disconnection of active shared drives. Listing all mapped network drives connected to the computer helps identify the correct target before disconnection.

Run the command below to view active connections.

PowerShell
Get-PSDrive -PSProvider "FileSystem"

Executing the command below disconnects the target drive once the assigned letter is identified.

💻Code
Remove-PSDrive -Name DriveLetter

Replace `DriveLetter` with the letter assigned to the target drive. For example:

💻Code
Remove-PSDrive -Name Z

Multiple drives disconnect using this syntax:

PowerShell
Get-PSDrive X, W | Remove-PSDrive

That completes the setup process.

Summary:

  • Mapping or unmapping shared network drives using PowerShell in Windows 11 provides a convenient and efficient way to manage access to network resources.
  • Following the steps, users can easily map network drives and access shared folders, streamlining their workflow and enhancing productivity.
  • Including credentials with the PowerShell command or storing them in the Credential Manager offers flexibility and security when mapping network drives.
  • Additionally, PowerShell enables users to efficiently list and disconnect mapped network drives, providing a comprehensive solution for managing network resources on Windows 11.

Was this guide helpful?

Tags: #Windows 11
Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Map Network Shares as Drives in Windows 11
Windows How to Map Network Shares as Drives in Windows 11
How to Map Local Folders as Drives in Windows 11
Windows How to Map Local Folders as Drives in Windows 11
How to Change PowerShell Execution Policies in Windows 11
Windows How to Change PowerShell Execution Policies in Windows 11
How to Use Access Keys in Windows 11 File Explorer
Windows How to Use Access Keys in Windows 11 File Explorer

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *