0

I'm running windows 10 pro.

I have a powershell script that starts every day at midnight and runs all day. It's controlled by the Task Scheduler. The script itself works fine and in the event of an error exits with code 1

The task definition is ....

Powershell.exe -file "c:\\my_dir\\my_script.ps1"

The script fails occasionally, I've ticked box 'if the task fails restart every...' and set it to try 5 times at 1 minute intervals.

There are some posts on this subject that suggest it was a known fault about 7-8 years ago. I am doing something wrong or have microsoft really not fixed this in all that time?


UPDATE - If successfully starting a job, and then receiving an exit code (any exit code) constitutes success, what exactly does the task scheduler regard as a failure? Under what circumstances will the task scheduler attempt a restart?

The powershell script is somewhat complex and under configuration control so editing it would be a non-trivial problem.

1 Answers1

0

The fact that scheduler starts powershell successfully and receives an exit code is considered a success as far as Task Scheduler is concerned.

If you want it to retry you should build the exception handling into your script or have a separate script to check the error codes from previous runs and rerun as necessary.

Harrison Gibbs
  • 369
  • 1
  • 8