-1

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!

  • If you exit PowerShell, is the drive mapping retained, and available, after you start a new PowerShell session? If you exit the PowerShell session, and then log out (but do not reboot), does the mapping persist, or get reconnected, when you log back in? – Jeff Zeitlin Jan 02 '20 at 18:19
  • This is how you map a persistent drive. I think something else operationally is probably going on here, you'd likely get better assistance over at https://superuser.com. – Bender the Greatest Jan 02 '20 at 18:38
  • @JeffZeitlin When I exit PowerShell, the drive mapping is retained and available. If I log out and back in, the mapping persists. It is only when rebooting that the mapping does not persist. – Benjamin Baxley INAP Jan 02 '20 at 21:00
  • @BendertheGreatest Thanks for the tip, I'll ask over there as well. – Benjamin Baxley INAP Jan 02 '20 at 21:01
  • @JeffZeitlin Whoops, I made a mistake. I thought when logging out and back in, the mapping persisted. That was when I manually mapped the drive in testing. I verified that the mapping persists when the PowerShell session is closed, but it does NOT persist when logging out and back in. – Benjamin Baxley INAP Jan 02 '20 at 21:50
  • See the answers to [this question](https://stackoverflow.com/questions/49201332/powershell-new-psdrive-persist-between-login). One recommendation was to [dot-source](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scripts?view=powershell-6#script-scope-and-dot-sourcing) the script to persist the connection. – Rich Moss Jan 02 '20 at 22:11
  • @RichMoss Dang, I was hoping to not have to dot-source -_- if I must, I must. Thank you for these links! – Benjamin Baxley INAP Jan 02 '20 at 22:23
  • @RichMoss That first link actually had the fix for me, thank you! 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! – Benjamin Baxley INAP Jan 02 '20 at 22:52

1 Answers1

0

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!