How to send email when SPECIFIC scheduled task fails to run or returns with an error code

scheduled-tasktask-schedulerwindows-server-2008

I have a backup script (Powershell 1.0) that is executed every night by the Task Scheduler on my Windows 2008 box. If that script should fail to start, e.g. because the script has been moved or something similar, or if the script fails during execution, I would like to get a email notification.

There are many examples of getting Task Schedular to send an email based on an event log entry. However, I only want to be notified if MY particular scheduled task fails, not get a notification for all tasks that fails with an EventID 203/103/201. How can I do that without any custom software?

Best Answer

You have to edit it in xml.

So for example

<QueryList>
  <Query Id="0" Path="Microsoft-Windows-TaskScheduler/Operational">
    <Select Path="Microsoft-Windows-TaskScheduler/Operational">*[System[(EventID=103 or EventID=201 or EventID=203)]]</ and *[EventData[Data and (Data='PUT TASK NAME HERE')]]
    </Select>
  </Query>
</QueryList>