Search code examples
pythonpowershellscheduled-taskswindows-task-scheduler

Task scheduler not producing output with powershell script


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


Solution

  • Changing the arguments option has worked:

    Add arguments (optional):

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