EDIT: Alt title: New-PSDrive in Powershell not working the same as NET USE in bat

I'm trying to load a python script in WinPython off a UNC Path, so I need to map it to a drive. I have all this working in a bat file but can't get it to work in Powershell.


NET USE P: "\\networkPath\WinPython\WinPython-32bit-"
"P:\python-3.6.1\python.exe" "P:\loadRemix3D.pyw"


New-PSDrive -Name P -PSProvider FileSystem -Root \\networkPath\WinPython\WinPython-32bit-
Push-Location -Path P:\    
Start-Process -FilePath P:\python-3.6.1\python.exe -WorkingDirectory P:\python-3.6.1 -ArgumentList P:\loadRemix3D.pyw

The pathing is correct as in the Powershell correctly executes Python and loads the Python script, but the Python script's pathing behaves as though I loaded it directly from UNC.

How do I make the Powershell work the same as the bat?

EDIT: As per Jeff's answer, here is a working version of the Powershell script:

NET USE P: "\\networkPath\WinPython\WinPython-32bit-"
Push-Location -Path P:\
Start-Process -Wait -FilePath "P:\python-3.6.1\pythonw.exe" -WorkingDirectory "P:\python-3.6.1" -ArgumentList "P:\loadRemix3D.pyw"
NET USE P: /delete /y

The only other thing I needed to add was to explicitly delete the mapping since it appears that NET USE mappings persist in the global PowerShell context(?).

  • 1
    you could just add -persist to your New-PSDrive. This will send the PSDrive to your Filesystem. In some PowerShell Versions you also would need to specify -scope Global – SimonS Jun 12 '17 at 9:21

Drives created using Powershell's FileSystem provider (i.e., New-PSDrive -PSProvider FileSystem) are not visible to "outside" processes, and get 'expanded' to their root when passed to such an outside process. Instead, use the same NET USE command that you do for the batch version of the program.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.