powershellnetwork-programmingdrivepersistnew-psdrive

PowerShell mapped network drives not persisting after reboot


The command I'm running to map a network drive is:

New-PSDrive -Name "M" -PsProvider "FileSystem" -Root "\\domain.com\filepath" -Persist -Scope Global -Credential $userCredentials

The command maps the drive and the connection persists after closing the script, but after rebooting the drive disappears. I'm under the impression that adding the global scope supersedes the need for dot-sourcing, which I'd rather not do for the sake of this script.

Thanks in advance for your suggestions/answers!


Solution

  • To anyone else who gets to this question: after the drive is mapped, in the user registry under HKCU\Network[drive letter] there are two keys that need value changes BEFORE logging out and back in:

    Change the DWORD value of ConnectionType to 1, and the DWORD value of DeferFlags to 4. This magically fixed it for me, so the drive persists!