Forum Discussion
Mark_Block
Feb 03, 2022Copper Contributor
Externally trigger a .ps1 to exit
I'm running a .ps1 from Task Scheduler. If I stop the script from the Task Scheduler console with the End command, does that generate an event/trigger that the script can react to? (I'd like the scri...
- Feb 09, 2022taking action within the script when an external action has stopped the scheduled job - no, this isnt possible.
Mark_Block
Feb 09, 2022Copper Contributor
It seems I'm explaining this badly. I'm not losing the output written by Write-Output. Also, running the script more frequently won't solve the problem. The problem is that the script doesn't know it's being shut down. (BTW, I solved the problem using an external semaphore file that the script checks but I'm still wondering if there's a more "elegant"). I'll try to explain again.
When the script is shut down by an external action, like hitting End from Task Scheduler, the script has no idea it's being shut down. I need a method that allows the script, from inside the script, to know it's being shut down.
When the script is shut down by an external action, like hitting End from Task Scheduler, the script has no idea it's being shut down. I need a method that allows the script, from inside the script, to know it's being shut down.
Jonathan_Allen
Feb 09, 2022Brass Contributor
taking action within the script when an external action has stopped the scheduled job - no, this isnt possible.
- Mark_BlockFeb 09, 2022Copper ContributorOK. That was my conclusion as well. Thanks for your help.