Friday, 1 September 2017

powershell - Mapped Drive inaccessible from Windows Scheduled task


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::[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
PSDriveCommand

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.



Answer



Using


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

Apparently allowed the schedule task to see the drive normally.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...