Powershell mapped network drive doesn't persist

Posted by Davidw on Super User See other posts from Super User or by Davidw
Published on 2013-10-20T02:52:02Z Indexed on 2013/10/20 3:58 UTC
Read the original article Hit count: 398

I'm trying to create a script that maps a network drive whenever I connect to a VPN, then disconnects the drive when I disconnect from the VPN, using Task Scheduler to launch the script when the event is created.

It launches the script, which creates the drive, but when Powershell closes, it disconnects the drive, so it only stays open for a few seconds, then closes it again. I have the persist parameter specified, but it doesn't persist.

New-PSDrive -Name "N" -PSProvider FileSystem -Root \(Serverpath)\ndrive -Persist

© Super User or respective owner

Related posts about powershell

Related posts about windows-task-scheduler