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.
In this guide, you will learn the steps 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.
How to map network drive on PowerShell
To map a network drive with PowerShell, 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 drive 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.
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 it will appear in File Explorer.
How to map network drive with credentials on PowerShell
To map a network drive providing the account name and password, use these steps:
-
Open Start.
.Windows_Software_Technology-Big-343{display:inline-block;width:300px;height:600px}@media(min-width: 500px){.Windows_Software_Technology-Big-343{width:300px;height:600px}} -
Search for PowerShell and click the top result to open the console.
-
Type the following command to create a variable with the credentials you want to use 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.
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 trying to connect using credentials, you will always get prompted to provide a password manually. If you want 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 use the same command without the -Crendtial
option like this: New-PSDrive -Name "E" -Root "\\vm-beta\ShareOne" -Persist -PSProvider "FileSystem"
You can create a new entry in Credential Manager using this command: cmdkey /add:pcname /user:network\username /pass:password
How to 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 for the drive letter of the mapping.
For example, this command disconnect 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.
Post a Comment