1

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?

Jon
  • 11
  • 3
  • Where is the script you require us to help you to fix? Please, when [editing your question](https://stackoverflow.com/posts/61069935/edit), note that, your linked question mentions `powershell` which is not tagged in your question. If you think that [[tag:powershell]] may be relevant please include it when updating your question post. – Compo Apr 06 '20 at 22:42
  • Take the [tour], read [ask] and [mcve]. [Server Fault](https://serverfault.com/) might be a better venue for this question. – jwdonahue Apr 07 '20 at 03:37

0 Answers0