# Windows – Running powershell script through Windows Task Scheduler

I'm trying to run a simple PS1 powershell script from the Task Scheduler. The task's Actions settings are Program: powershell and Add arguments: -executionpolicy bypass -file C:\Users\Robin\Documents\script.PS1.

The objective script.PS1 is accessed ok but a line within it (a call to another script: Rscript Z:\rscript.R) fails with the message:

Fatal error: cannot open file Rscript Z:\rscript.R
'rscript.R': no such file or directory


If I run the same line manually in Powershell it works ok. Moreover the following runs fine as a Run command: powershell -executionpolicy bypass -file C:\Users\Robin\Documents\script.PS1, which suggests the problem is in Task Scheduler. The task is set to run with highest privileges. I'm stumped.

Very grateful for assistance.

2. Map the network drive early on in your script (in PowerShell 3 you could use New-PSDrive, but), the simplest way is to run the NET USE Z: \\SERVER\SHARE command. Of course, you might need to add user credentials: password /USER:domain\user and you could also try adding /SAVECRED /PERSISTENT:YES and running that command once and hoping it sticks (but I'd still test-path and remap it if that's an option).