I am working with python 2.7.9 (64 bit) and windows server 2012 R2

I am trying to set up a windows scheduled task to run a lengthy python script every day. I've managed to by calling the python from a powershell script get the python to run successfully however there comes a problem when it is trying to access a mapped drive.

I can access the drive fine from the command line or interactive powershell and it works if I invoke the powershell script directly, but when I run the scheduled task I get an error:

bsd_runner.py:<module>:[Errno 2] No such file or directory: u'S:\\pre/RefAttendanceReason.csv'

Even though the task is set to run as my user I figured maybe the schedule task doesn't have the drive mapped so I looked into mapping the drive inside of my powershell script. I tried:

New-PSDrive –Name "S" –PSProvider FileSystem –Root "\\D-DWSQL01\Share\load" –Persist 2>&1 >> map_drive.log

which got me the results:

New-PSDrive : The specified drive root "â€Root \\D-DWSQL01\Share\load 
â€Persist" either does not exist, or it is not a folder.
At C:\Users\thomasa\Desktop\sandbox\BSD_ETL\run_bsd.ps1:8 char:5
+     New-PSDrive –Name "S" –PSProvider FileSystem –Root 
"\\D-DWSQL01\Share\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ReadError: (â€Name S â€PSProvider:PSDriveInfo) [ 
   New-PSDrive], IOException
    + FullyQualifiedErrorId : DriveRootError,Microsoft.PowerShell.Commands.New 

again works fine if I run the command directly but has an issue running through the scheduled task.

I checked highest permissions and told the task to make sure it had access to the network before running but to no avail.

I tried unmapping the drive and running the powershell script manually and got the same error for the drive root not existing. But I mapped it myself and it proceeds just fine.



net use S: \\D-DWSQL01\Share\load

Apparently allowed the schedule task to see the drive normally.


before PSdrive connection add a line:

pushd \\D-DWSQL01\Share\load

before disconnecting by PSdrive add a line:


PSdrive commands may be removed if you do not need map special drive letter.

  • 1
    Could you explain how this answers the question? – suspectus Nov 6 '15 at 9:15

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.