List Scheduled Tasks That Failed to Run

Lists all the scheduled tasks on a set of servers that failed to execute in the past three days.

 
 
 
 
 
4 Star
(4)
Add to favorites
Operating System
8/10/2009
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Works great and highly useful, thank you
    2 Posts | Last post March 28, 2018
    • I'm using this to monitor a domain's scheduled tasks.
      Here's an addition for ssl usage if needed as I did (also includes the user auth but hashed out).
      
      If ($c -gt 0) { 
                      #Email the files that will deleted later in this script             
                  
                      $smtpServer = "SMTPSERVER"
                      $sslOn = $true #SMTP server needs SSL should set this
                      $mailer = new-object Net.Mail.SMTPclient($smtpserver)
                      #$mailer.Credentials = new-object Net.NetworkCredential("UserId", "UserPassword", "UserDomain")
                      $mailer.EnableSsl = $sslOn             
                      $From = "Windows-Task-Scheduler@YOUR.NETWORK" 
                      $To = "ADMINS@YOUR.NETWORK" 
                      $subject = "$c Task Failures in the last 3 days" 
                      $msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)   
                      $msg.IsBodyHTML = $true 
                      $mailer.send($msg) 
                      } 
    • Had to make some additions within Windows to run this as a scheduled task.
      Now running perfectly automatically. Thank you
      
      Added sym links to C:\Windows\System32 due to running scheduled task as system and elevated permissions.
      ScheduleTaskMon.csv
      scheduletaskServers.txt
      
      I use HardLinkShellExt to make it easy.
  • Very useful, thank you!
    1 Posts | Last post August 13, 2015
    • I used this script to monitor scheduled tasks in our environment. I actually scheduled the script as a…scheduled task :) there for I needed to add a filter to exclude current running tasks: -and $_."Last Result" -ne 0 -and $_."Last Result" -ne 267009
      
      I also wanted to get rid of the system generated scheduled tasks, add only custom defined tasks in the report: -and $_.Author -notmatch "microsoft|N/A|Author|Operating System
      
      Also added the style element so that the mail is nicely formatted:
      a = "" 
      $a = $a + "<BODY {background-color:grey;}>" 
      $a = $a + "<STYLE TYPE='text/css'>"
      $a = $a + "<!--"
      $a = $a + "H2{font-family: Arial; font-size: 14pt} "
      $a = $a + "TD{font-family: Arial; font-size: 10pt;border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:red}"
      $a = $a + "TH{font-family: Arial; font-size: 10pt; border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
      $a = $a + "TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
      $a = $a + "--->"
      $a = $a + "</STYLE>"
      $a = $a + ""
      
  • System Task & Disable Task
    3 Posts | Last post August 13, 2015
    • Hi
      
      The script is very usefull but do you know if it's possible to filter all the system scheduled task (the one in the \Microsoft\Windows folder) ?
      i only want to know the failed sheduled task i created
      
      Otherwise, i still receveive the email for disable task 
      
      Regards
    • it s ok for the Disable task, i've just modified the filter "Schedule" to "Scheduled Task State"
      
      and for the system task i used the "notlike" argument
    • I use a filter on author to clear out the system scheduled tasks: -and $_.Author -notmatch "microsoft|N/A|Author|Operating System
  • Script does not read from text file.
    1 Posts | Last post July 01, 2014
    • I made the modifications outlined below and it works great if there is only a single server listed in the text file.
      
      Any idea what I would be doing wrong and why it's not reading the 2nd or 3rd server ive listed?
  • Blank Line
    1 Posts | Last post October 08, 2013
    • Hi
      
      The script running welle but the result sqhow 405 failed entruies ... but all are blank and oinly 2 are really failed
      
      Any ideas please ??
      
      Failed Scheduled Tasks since 07/10/2013 14:01
      HostName	TaskName	Last Run Time	Next Run Time	Task To Run
      HostName	TaskName	Last Run Time	Next Run Time	Task To Run
      HostName	TaskName	Last Run Time	Next Run Time	Task To Run
      HostName	TaskName	Last Run Time	Next Run Time	Task To Run
      HostName	TaskName	Last Run Time	Next Run Time	Task To Run
      HostName	TaskName	Last Run Time	Next Run Time	Task To Run
      HostName	TaskName	Last Run Time	Next Run Time	Task To Run
      HostName	TaskName	Last Run Time	Next Run Time	Task To Run
      
  • do you have a workaround for this issue please ?
    1 Posts | Last post September 12, 2013
    • I got this error when i launch this script command :
      PS E:\POWERSHELL> schtasks /query /s $svr /FO CSV /NH
      ERROR: /NH switch cannot be used with the LIST format.
      Type "SCHTASKS /QUERY /?" for usage.
  • $errors object doesn't have a 'count' property
    2 Posts | Last post May 07, 2013
    • running the script in debugger, the $errors object doesn't appear to have a count property, at least when it only contains 1 entry.  Therefore, the email doesn't get sent, cause $errors.count is null (or whatever value equates to null in powershell), so $c is also converttopowershell(null), and the conditional to branch into the email send routine evaluates false.
    • changed the line:
      $c = $errors.count
      
      to:
      $c = @($errors).count
      
      and am now getting the proper value.
  • Filter on Task Name
    1 Posts | Last post July 15, 2010
    • Nice script.  I am using it to track failures for scheduled Backups.   First make the changes Shawn suggested.  Next add -and $_."TaskName" -match "^*.Backup.*" to your second Where-object filter and then make sure your task name includes "Backup" somewhere in the name.  You may want to remove the error count, change the subject of your email, and modify your secondary HTML heading as well.  I also narrowed it down to 24 hrs and include the failure code in the email report.
      
      This way I can run the report for just the group of people that need to be notified of backup failures... or any other task for that matter.
  • ."Last Run Time" -lt $Dateminus Problem
    4 Posts | Last post May 07, 2010
    • For some reason, in the line
      
      $errors = Import-Csv ScheduleTaskMon.csv | 
      Where-Object {  $_."Schedule" -ne "Disabled" -and $_."Last Result" -ne 0}
      
      sometimes the
      ."Last Run Time" -lt $Dateminus
      where-object filter causes all rows to be filtered out.
      
      So that even though there are rows that fall into the date range, that have a last result other than 0, they are not included in the result set.
    • The problem line is actually
      
      $errors = Import-Csv ScheduleTaskMon.csv | 
      Where-Object {$_."Last Run Time" -lt $Dateminus -and $_."Schedule" -ne "Disabled" -and $_."Last Result" -ne 0}
      
    • The reason for that being rows are being filtered out unless they are older than the cut-off date.  You really want rows newer.
      
      As it is only rows that failed more than three days ago, rather than within the last three days are reported.
      
      In the problem line change the -lt to -gt
      
      $_."Last Run Time" -gt $Dateminus
    • You need to make that change in more than once place.
  • Login to SMTP
    1 Posts | Last post April 20, 2010
    • If you need to authenticate to your SMTP server to send mail you can set the credentials.
      
      If ($c -gt 0) {
                      #Email the files that will deleted later in this script            
                 
                      $smtpServer = "SMTPSERVER"
                      $mailer = new-object Net.Mail.SMTPclient($smtpserver)
      		$mailer.Credentials = new-object Net.NetworkCredential("UserId", "UserPassword", "UserDomain")             
                      $From = "Windows-Task-Scheduler@YOUR.NETWORK"
                      $To = "ADMINS@YOUR.NETWORK"
                      $subject = "$c Task Failures in the last 3 days"
                      $msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)  
                      $msg.IsBodyHTML = $true
                      $mailer.send($msg)
                      }