Post

Map a Network Drive with New-PSDrive

Map a persistent Windows network drive from PowerShell with New-PSDrive.

Use New-PSDrive to map a network share to an available Windows drive letter. Run the command in the user context that needs the mapped drive. Add credentials only when the current Windows session does not already have access to the share.

Required parameters to create a network connection:

ParameterDescription
NameMust be an available drive letter
PSProviderSet to FileSystem for network shares and folders
RootThe network location that you want to map
PersistMakes the drive available outside PowerShell, including File Explorer
1
New-PSDrive -Name V -PSProvider FileSystem -Root \\VM-server\Folder-01 -Persist

To provide alternate credentials, collect them interactively rather than storing a password in the script:

1
2
$credential = Get-Credential
New-PSDrive -Name V -PSProvider FileSystem -Root \\VM-server\Folder-01 -Persist -Credential $credential
This post is licensed under CC BY 4.0 by the author.