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:

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.