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.
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.
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.
New-PSDrive -Name "DRIVER-LETTER" -PSProvider "FileSystem" -Root "\\DEVICE-NAME-OR-IP\SHARED-FOLDER" -Persist
New-PSDrive -Name "E" -PSProvider "FileSystem" -Root "\\vm-beta\ShareOne" -Persist

Map network drive with credentials on PowerShell
To map a network drive providing the account name and password on Windows 11, use these steps:
Search for PowerShell and click the top result to open the console.
$cred = Get-Credential -Credential USERNAME

Confirm your account password.
Click the OK button.
New-PSDrive -Name "E" -Root "\\DEVICE-NAME-OR-IP\SHARED-FOLDER" -Persist -PSProvider "FileSystem" -Credential $cred
New-PSDrive -Name "E" -Root "\\vm-beta\ShareOne" -Persist -PSProvider "FileSystem" -Credential $cred

Disconnect mapped network drive on PowerShell
To disconnect and remove a mapped network drive with PowerShell, use these steps:
Search for PowerShell and click the top result to open the console.
Get-PSDrive -PSProvider "FileSystem"
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

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.
Why You Can Trust Pureinfotech
I have a key-value pair collection in groovy, in a Jenkins pipeline e.g.
def procedureParameters = [:]
procedureParameters.put('key','value')I’m trying to pass it to a powershell script –
def exitCode = powershell """ \$parameters = @{ ${procedureParameters} }
"""The above is just an (not working) example, but in the end I want to have a hashtable in powershell that reflect the groovy map that I have.
I have no problems passing a single variable to powershell. But I couldn’t find a way to do that with a collection. Is there a good way to do that, before I start serializing my map to string and then deserializing it on the powershell side?
After much trial and error, here’s a working solution. It still requires to serialize the map into a string. But at least no further processing is required on the powershell side. That’s the groovy pipeline code :
def powershellInput = "@{"
procedureParameters.each { key, value -> powershellInput += "\"$key\"=\"$value\"; "
}
powershellInput += "}"
powershell
""" [HashTable]$parameters = ${powershellInput}
"""Another option would be passing it to powershell in an environment variable. But I wasn’t able to make it work.
Palin Revno
4 silver badges11 bronze badges

In Windows 10, you can use PowerShell to remap a network drive. Below are the PowerShell commands to achieve this:
Explanation of the variables:
$DriveLetter: The desired drive letter for the network drive.$NetworkPath: The full path to the shared folder.$Username: Your username for accessing the shared folder.$Password: Your password for accessing the shared folder.



