Morning Thwack Community....
We have a scheduled task monitor:
$events = get-scheduledtask | where {$_.State -ne "Disabled"} | where {((Get-ScheduledTaskInfo $_).LastTaskResult -ne "0") -and ((Get-ScheduledTaskInfo $_).LastTaskResult -ne "267009") -and ((Get-ScheduledTaskInfo $_).LastRunTime -ge ((Get-Date).AddHours(-48)) -and ((Get-ScheduledTaskInfo $_).TaskPath -notlike "\Microsoft\*" ))} | Select TaskName$count = ($events.TaskName).Countif ($count -ge 1){ Write-Host "Message: Scheduled task has failed :" $events.TaskName Write-Host "Statistic: $count"}else{ Write-Host "Message: No Errors reported" Write-Host "Statistic: $count" }
This will alert when any non disbaled task has an exit code not of 0. The problem is, if a task has failed previously and then its in a running state during the next poll it will cause the script to assume the task is ok and thus cause it to produce a false positive. If LastTaskResult was actually the result of the last run and didn't display a running state we would be ok.
Is there a way of passing the previous message & statistic of a compant into a monitoring script? That way I could check if it was previously failed and ignore the running state - keeping the alert active.
Alternativly I could write the result to a file on the server and check via that - though I don't really like this way
Does anyone else have any other ideas?
Thanks
Rob