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
- Map network drive with credentials on PowerShell
- Disconnect mapped network drive on PowerShell
Map network drive on PowerShell
To map a network drive with PowerShell on Windows 10, use these steps:
-
Open Start on Windows 10.
-
Search for PowerShell and click the top result to open the console.
-
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
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:
-
Open Start.
-
Search for PowerShell and click the top result to open the console.
-
Type the following command to create a variable with the proper credentials, and press Enter:
$cred = Get-Credential -Credential USERNAME
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. -
Confirm your account password.
-
Click the OK button.
-
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
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:
-
Open Start.
-
Search for PowerShell and click the top result to open the console.
-
Type the following command to view all the mapped drives and press Enter:
Get-PSDrive -PSProvider "FileSystem"
-
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
-
(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.