I have a batch file that syncs a folder to S3 bucket on a scheduled task. I want another schedule task to trigger when the batch file fails to run or scheduled task fails in any way and notify me via email.
I saw a related post, but I haven't been able to get it right. How get task scheduler to detect failed error code from powershell script
tldr: A scheduled task will return Event ID 102 (Task completed) even if the batch program internally fails. Supposedly, ResultCode in the EventData gets logged correctly, and can be queried to use it as trigger.
How do I make a custom trigger to detect a scheduled task failure to send myself am email?
edit: If the question was ambiguous, I'm trying to achieve custom filter via windows scheduled task as shown below.
Windows schedule task custom trigger
<QueryList>
<Query Id="0" Path="Microsoft-Windows-TaskScheduler/Operational">
<Select Path="Microsoft-Windows-TaskScheduler/Operational">
*[System[(Level=4 or Level=0) and (EventID=201)]]
and
*[EventData[Data[@Name='ResultCode'] and (Data='2147942401')]]</Select>
</Query>
</QueryList>
This was an example I found in the link above, but I was not able to accomplish catching internally failed batch file task as mentioned. How do I create a custom filter that will capture internal error via Result Code in EventData?