Map Drive From Command Line - Portable

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:

$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 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: PowerShell uniquely allows mapping a network share to