1

How can I setup an email notification to myself when task scheduler not failed but completed "with return error code...".

Again, log file doesn't say Error, it says Action completed.

The only difference difference between truly successful completion and not in a log file is "with return code ..."

enter image description here

Serdia
  • 4,242
  • 22
  • 86
  • 159

1 Answers1

1

Since you've tagged powershell, you could do something like this.

Get-WinEvent -FilterHashtable @{Logname='Some log name'} |
    Where-Object message -match 'with return code (?<ErrorCode>.+?)\.' |
        Foreach-Object {
            # Send mail code here
            Send-MailMessage ...

            # Some info that may be useful
            $_.TaskDisplayName
            $_.TimeCreated
            $_.MachineName
            $matches.ErrorCode

        }
Doug Maurer
  • 8,090
  • 3
  • 12
  • 13