How to map network drive using PowerShell on Windows 10

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 tutorial 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-IPSHARED-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-betaShareOne" -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.

READ MORE  Fix Audio Problems Windows 11/10

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: networkadmin 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-IPSHARED-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-betaShareOne" -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.

READ MORE  Windows 10 build 19045.3570 (KB5031356) outs for version 22H2, 21H2

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-betaShareOne" -Persist -PSProvider "FileSystem"

You can create a new entry in Credential Manager using cmdkey /add:pcname /user:networkusername /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.

READ MORE  How one can repair any Wi-Fi downside on Windows 10

Here is why you should trust Winkeys.

We may earn commission for purchases using our links to help keep offering the free content. Privacy policy info.

All content on this site is provided with no warranties, express or implied. Use any information at your own risk. Always backup of your device and files before making any changes. Privacy policy info.

      Select your currency
      WinKeys
      Logo
      Register New Account