How to map network drive using PowerShell on Windows 10

You can use PowerShell to map and disconnect network drives on Windows 10, and here's how.

PowerShell map network drive
PowerShell map network drive

Windows 10 provides multiple ways to map a network drive on your computer, including using PowerShell, which can come in handy when creating a script or when you prefer using a command-line interface.

When you use PowerShell (or any other methods, such as Command Prompt or File Explorer) to map a network-shared folder, the process will create a pointer to the destination folder that will appear in File Explorer as a drive with the letter you assigned it.

This guide will teach you how to use PowerShell to map a network drive on Windows 10. In addition, we will outline the steps to disconnect the mapping when it is no longer needed.

Map network drive on PowerShell

To map a network drive with PowerShell on Windows 10, use these steps:

  1. Open Start on Windows 10.

  2. Search for PowerShell and click the top result to open the console.

  3. Type the following command to map a drive assigning letter manually and press Enter:

    New-PSDrive -Name "DRIVER-LETTER" -PSProvider "FileSystem" -Root "\\DEVICE-NAME-OR-IP\SHARED-FOLDER" -Persist

    In the command, replace “DRIVER-LETTER” with the drive letter not already in use you want to use. Then, change “DEVICE-NAME-OR-IP” and “SHARED-FOLDER” for the name of the computer name or IP address of the device hosting the shared folder and the name of the shared folder. For example, this command maps the ShareOne folder to the computer with the “E” drive letter:

    New-PSDrive -Name "E" -PSProvider "FileSystem" -Root "\\vm-beta\ShareOne" -Persist

    PowerShell map network drive on Windows 10

Once you complete the steps, the network shared folder will map on the computer and appear in File Explorer.

Map network drive with credentials on PowerShell

To map a network drive providing the account name and password on Windows 11, use these steps:

  1. Open Start.

  2. Search for PowerShell and click the top result to open the console.

  3. Type the following command to create a variable with the proper credentials, and press Enter:

    $cred = Get-Credential -Credential USERNAME

    Create credential variable with PowerShell

    Quick tip: If you are mapping a drive in Active Directory, remember to use the network name like this: network\admin to specify the account information.
  4. Confirm your account password.

  5. Click the OK button.

  6. Type the following command to map a drive assigning drive letter manually and press Enter:

    New-PSDrive -Name "E" -Root "\\DEVICE-NAME-OR-IP\SHARED-FOLDER" -Persist -PSProvider "FileSystem" -Credential $cred

    In the command, replace “DRIVER-LETTER” with the drive letter not already in use you want to use. Then, change “DEVICE-NAME-OR-IP” and “SHARED-FOLDER” for the name of the computer name or IP address of the device hosting the shared folder and the name of the shared folder. For example, this command maps the ShareOne folder to the computer with the “E” drive letter:

    New-PSDrive -Name "E" -Root "\\vm-beta\ShareOne" -Persist -PSProvider "FileSystem" -Credential $cred

    PowerShell map network drive with password

After you complete the steps, the command will authenticate and map the shared folder as a drive on Windows 10.

When connecting using credentials, you will always get prompted to provide a password manually. To avoid this step, you could store the password in an encrypted file on the computer and query that file using PowerShell. Or you can speed up the process by storing the remote host account name and password in Credential Manager and then using the same command without the -Crendtial option. For example, New-PSDrive -Name "E" -Root "\\vm-beta\ShareOne" -Persist -PSProvider "FileSystem"

You can create a new entry in Credential Manager using cmdkey /add:pcname /user:network\username /pass:password command.

Disconnect mapped network drive on PowerShell

To disconnect and remove a mapped network drive with PowerShell, use these steps:

  1. Open Start.

  2. Search for PowerShell and click the top result to open the console.

  3. Type the following command to view all the mapped drives and press Enter:

    Get-PSDrive -PSProvider "FileSystem"
  4. Type the following command to disconnect the mapped network drive and press Enter:

    Remove-PSDrive -Name DRIVE-LETTER

    In the command, replace “DRIVE-LETTER” with the drive letter of the mapping. For example, this command disconnects the “E” drive:

    Remove-PSDrive -Name E

    PowerShell disconnect map drive

  5. (Optional) Type the following command to disconnect multiple mappings and press Enter:

    Get-PSDrive DRIVER-LETTER-1, DRIVE-LETTER-2 | Remove-PSDrive

    In the command, replace “DRIVER-LETTER-1” and “DRIVE-LETTER-2” with the drive letters you want to disconnect. For example, this command disconnects the “E” and “F” drives:

    Get-PSDrive E, F | Remove-PSDrive

Once you complete the steps, the drive mapping will be removed from the computer.

About the author

Mauro Huculak is a Windows expert and the Editor-in-Chief who started Pureinfotech in 2010 as an independent online publication. He is also been a Windows Central contributor for nearly a decade. Mauro has over 12 years of experience writing comprehensive guides and creating professional videos about Windows, software, and related technologies, including Android and Linux. Before becoming a technology writer, he was an IT administrator for seven years. In total, Mauro has over 20 years of combined experience in technology. Throughout his career, he achieved different professional certifications from Microsoft (MSCA), Cisco (CCNP), VMware (VCP), and CompTIA (A+ and Network+), and he has been recognized as a Microsoft MVP for many years. You can follow him on X (Twitter), YouTube, LinkedIn and About.me.