I'm trying to run a PowerShell script every minute using Task Scheduler. The script basically fires off an HTTP GET request and I want to have the task show the "Run Result" as an error if the request is not successful.
Right now, no matter what happens in my script, the Task Scheduler is showing the last "Run Result" as "Success", and I'm not sure what I should be doing to make it work properly. In my script, I am using Exit 1
if the request does not return a 200/OK, and Exit 0
otherwise.
My Task action is set up as follows:
- Action: Start a program
- Program/script:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
- Add arguments:
-NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "C:\MyScript.ps1; Exit $LASTEXITCODE"
- Start in:
C:\