Script to Get Information on SharePoint Timer Jobs That Ran Between a Date Range

The following script helps find timer jobs that ran within the last minute. You can modify $date.AddMinutes(-1) to the number you would like to get the details for.

# Get current date

$date = Get-Date

 

Write-Host "Looking for jobs that ran with a Last Run Time of greater than or equal to" $date.AddMinutes(-1) " and less than or equal to" $date

 

# Get all Timer jobs and iterate

Get-SPTimerJob | ForEach-Object {

 

  # Get last run time for job

  $lastRunTime = $_.LastRunTime

 

  # If run time is between the date range write it out

  if ($lastRunTime -ge $date.AddMinutes(-1) -and $lastRunTime -le $date )

  {

     Write-Host $_.Name", last run at" $_.LastRunTime

  }

}

The result may be as in the following:

PS E:\Users\Administrator> D:\Veena Book\PS Scripts\Current running timer jobs.ps1

Looking for jobs that ran with a Last Run Time of greater than or equal to 29-04-2013 10:03:45 and less than or equal to 29-04-2013 10:04:45:

  • SchedulingUnpublish , last run at 29-04-2013 10:03:56
  • MySite-Second-Instantiation-Interactive-Request-Queue , last run at 29-04-2013 10:04:33
  • MySite-Instantiation-Interactive-Request-Queue , last run at 29-04-2013 10:04:18
  • job-upgrade-sites , last run at 29-04-2013 10:03:56
  • SchedulingApproval , last run at 29-04-2013 10:04:03
  • MySite-Instantiation-Non-Interactive-Request-Queue , last run at 29-04-2013 10:04:19
  • SchedulingUnpublish , last run at 29-04-2013 10:03:55
  • MySite-Second-Instantiation-Interactive-Request-Queue , last run at 29-04-2013 10:04:19
  • EducationBulkOperationJob , last run at 29-04-2013 10:04:39
  • MySite-Instantiation-Interactive-Request-Queue , last run at 29-04-2013 10:04:22
  • job-upgrade-sites , last run at 29-04-2013 10:04:06
    ……..
  • Rebalance crawl store partitions for 5809de9d-cd12-4c32-94c2-c03c6eb67189 , last run at 29-04-2013 10:04:00
  • job-diagnostics-performance-metric-provider , last run at 29-04-2013 10:04:00
  • job-diagnostics-sql-performance-metric-provider , last run at 29-04-2013 10:04:00
  • User Profile Service Application_ProfileSynchronizationJob , last run at 29-04-2013 10:04:00
  • WMAExchangeSync_61a42768-d43f-44ab-904c-4f81238bd074 , last run at 29-04-2013 10:03:56
  • PS E:\Users\Administrator>

List of Failed jobs

You can modify the script to get the failed jobs. The following script helps to get the list of failed or aborted timer jobs:

# Get current date

$date = Get-Date

 

Write-Host "Looking for jobs that ran with a Last Run Time of greater than or equal to" $date.AddMinutes(-1) " and less than or equal to" $date

 

# Get all Timer jobs and iterate

Get-SPTimerJob | ForEach-Object {

 

  # Get last run time for job

  $lastRunTime = $_.LastRunTime

 

  # Check If run time is between the date range

  if ($lastRunTime -ge $date.AddMinutes(-1) -and $lastRunTime -le $date )

  {

    # Write-Host $_.Name", last run at" $_.LastRunTime

    # Get only these jobs history entries

      $HistoryEntries = $_.HistoryEntries

     #Iterate for these jobs

     $count = 0;

      foreach($a in $HistoryEntries) {

       

        $HistStartTime = $a.StartTime

        $HistEndTime = $a.EndTime

        # Check for history entries

    

        if ($HistStartTime -ge $date.AddMinutes(-1) -and $a.Status -ne "Succeeded")

        {

           $count++

           Write-Host $_.Name, $count

           Format-List -Property $_.Name; $a.Status; $a.ErrorMessage;

        }

       

     }

    }

   

  }

You may see results something as in the following.

Aborted

The administration service job definition "job-application-server-admin-service" (id 969183ca-7391-40b3-a398-1c1fbd6f781b) was not executed because the administration service on this server is not started. This job definition can be run manually using "stsadm -o execadmsvcjobs".

job-application-server-admin-service 242

Aborted

The administration service job definition "job-application-server-admin-service" (id 969183ca-7391-40b3-a398-1c1fbd6f781b) was not executed because the administration service on this server is not started. This job definition can be run manually using "stsadm -o execadmsvcjobs".

Health Statistics Updating 1

Failed

Microsoft SharePoint Foundation Usage service application not found.

Health Statistics Updating 2

Failed

Microsoft SharePoint Foundation Usage service application not found.