Map Drive From Command Line ((link)) May 2026

New-PSDrive -Name "Z" -PSProvider FileSystem -Root "\\server\share" -Persist This creates a drive visible in File Explorer and across all applications—identical to net use Z: \\server\share . PowerShell handles credentials more securely using PSCredential objects:

$cred = Get-Credential New-PSDrive -Name "Z" -PSProvider FileSystem -Root "\\server\share" -Credential $cred -Persist The Get-Credential dialog is secure, but for automation you can build a credential object (though storing passwords in scripts is still discouraged). PowerShell uniquely allows mapping a network share to a local folder path instead of a drive letter—something net use cannot do directly: map drive from command line

net use Z: \\server\share /user:DOMAIN\username MyPassword123 By default, a drive mapped via net use lasts only for the current user session. Log off, and it’s gone. To make a mapping persistent across reboots, add the /persistent:yes flag: Log off, and it’s gone

net use Z: \\server\share This maps the share \\server\share to drive letter Z: . If the share requires authentication, net use will prompt you for a username and password. But you can supply them inline for automation: But you can supply them inline for automation:

Similar Posts