0
votes

I have a basic task through Task Scheduler that calls a Powershell script that executes a Python Script. For some reason when I call the Powershell script through Task Scheduler it produces no output, when I look at the History logs it also successfully finishes as well. I am able to manually run the Powershell script through the terminal and everything works. Has anyone else had this issue? Thanks!

Here are my "Edit Actions" paramters:

Program/script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Add arguments (optional): -ExecutionPolicy Bypass C:\Users\MyUserName\Documents\MyFolderName\MyPowerShellScript.ps1

Start in (optional): C:\Users\MyUserName\Documents\MyFolderName\

The task is also configured in Windows Vista, Windows Server 2008 and will Run whether user is logged on or not

Here is what is in my .ps1 script:

$Path = "C:\Users\MyUserName\Documents\MyFolderName"
cd $Path
pipenv run python "main.py"

*edit I am getting error code 0x1 as the Last Run Result, it should be 0x0

1
Please, where's your Powershell script? - Marc Sances
@MarcSances C:\Users\MyUserName\Documents\MyFolderName\MyPowerShellScript.ps1 - dko512
I mean that you should paste the code of that script so we can see if it is related somehow.... - Marc Sances
@MarcSances The Powershell script works when I run it manually, it's just not working when I execute it with Task Scheduler. - dko512
Please edit your question to include the code. We need a minimal, reproducible example to help you out - Marc Sances

1 Answers

0
votes

Changing the arguments option has worked:

Add arguments (optional):

-ExecutionPolicy Bypass -file "C:\Users\MyUserName\Documents\MyFolderName\MyPowerShellScript.ps1"