Mapping Network Drives (Part 2)

by Aug 28, 2015

Beginning with PowerShell 3.0, you can use New-PSDrive to map network drives. They will be visible in File Explorer as well. Here is some sample code:

#requires -Version 3

New-PSDrive -Name N -PSProvider FileSystem -Root '\\dc-01\somefolder' -Persist 

Test-Path -Path N:\
explorer.exe N:\
Get-PSDrive -Name N

Remove-PSDrive -Name N -Force

If you’d like to provide logon credentials, add the –Credential parameter to New-PSDrive, and submit a username in the format domain\username. The password will be securely prompted.

Twitter This Tip! ReTweet this Tip!