How to get SharePoint Timer Job History using PowerShell?

sharepoint-2013-get-timer-job-history.png

In this post we will discuss how we can get SharePoint timer job history using PowerShell in SharePoint 2013.

Requirement: Retrieve and review the SharePoint timer job history for troubleshooting an issue.

Solution:

SharePoint 2013 Central Administration site provides an interface to review timer job history. Here are the steps to get SharePoint timer job history in SharePoint.

Read some SharePoint tutorials:

– Go to Monitoring -> Check Job status

sharepoint powershell get timer job history
sharepoint powershell get timer job history

– Click on “Job History” link from left navigation


sharepoint get timer job status powershell
sharepoint get timer job status powershell

– Under the “View” filter, choose “Job Definition”. You’ll find a cascading filter appears as “Job Definition” once you choose View filter as “Job definition”. You can also choose options such as: Service, Web Application, and Server.

sharepoint 2010 get all timer jobs powershell
sharepoint 2010 get all timer jobs powershell

– Under the “View” filter, choose “Job Definition”. You’ll find a cascading filter appears as “Job Definition” once you choose View filter as “Job definition”. You can also choose options such as: Service, Web Application, and Server.

sharepoint 2010 powershell get timer job history
sharepoint 2010 powershell get timer job history

– Click on the job definition filter to “change job definition”

sharepoint 2013 powershell get timer job history
sharepoint 2013 powershell get timer job history

– Pick the relevant timer job definition. E.g. Audit Log Trimming, Immediate Alerts, etc.

sharepoint powershell get timer job history
sharepoint powershell get timer job history

– Now, you’ll find the jobs history for selected timer job as below.

sharepoint get timer job status powershell
sharepoint get timer job status powershell

PowerShell script to search and export timer job history for a particular time period:

Why PowerShell? Well, the above central admin page provides the interface to analyze timer jobs associated with particular job or service, but there isn’t any easy way to get timer job history for a specific time period other than navigating page by page. So, let’s use PowerShell script to find and extract timer job history.



Get all timer jobs of a web application:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

# Variables

$WebAppURL = http://Test.contoso.com/default.aspx

$StartTime = “06/22/2016 01:00:00 AM” # mm/dd/yyyy hh:mm:ss

$EndTime = “06/24/2016 01:30:00 AM”

#Get all timer jobs associated with a web application

$WebApp = Get-SPWebApplication $WebAppURL

$Results = $WebApp.JobHistoryEntries |

where { ($_.StartTime -ge $StartTime) -and ($_.EndTime -le $EndTime) } |

Select JobDefinitionTitle,WebApplicationName,ServerName,Status,StartTime,EndTime

#Send results to Grid view

$Results | Out-GridView

Get timer job history for a specific timer job:

# Variables

$StartTime = “06/26/2016 01:00:00 AM” # mm/dd/yyyy hh:mm:ss

$EndTime = “06/26/2016 01:30:00 AM”

$TimerJobName = “Immediate Alerts”

#To Get Yesterday’s use:

#$StartDateTime = (Get-Date).AddDays(-1).ToString(‘MM-dd-yyyy’) + ” 00:00:00″

#$EndDateTime = (Get-Date).AddDays(-1).ToString(‘MM-dd-yyyy’) + ” 23:59:59″

#Get the specific Timer job

$Timerjob = Get-SPTimerJob | where { $_.DisplayName -eq $TimerJobName }

#Get all timer job history from the web application

$Results = $Timerjob.HistoryEntries |

where { ($_.StartTime -ge $StartTime) -and ($_.EndTime -le $EndTime) } |

Select WebApplicationName,ServerName,Status,StartTime,EndTime

#Send results to Grid view

$Results | Out-GridView

Failed Timer Jobs History Report:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

# Variables

$WebAppURL = http://Test.contoso.com

$StartTime = “01/01/2016 01:00:00 AM” # mm/dd/yyyy hh:mm:ss

$EndTime = “05/01/2016 01:30:00 AM”

$OutPutFile=”D:\FailedJobHistoryRpt.csv”

#Get all timer jobs associated with a web application

$WebApp = Get-SPWebApplication $WebAppURL

#Get all Failed Timer jobs in between given Time

$Results = $WebApp.JobHistoryEntries | Where {($_.StartTime -ge $StartTime) -and ($_.EndTime -le $EndTime) -and ($_.Status -ne ‘Succeeded’)}

#Export to CSV

$Results | Export-Csv $OutPutFile –NoType

write-host “Failed Timer jobs history Exported to CSV!” -F Green

Once done updating required URL, Open PowerShell ISE as Administrator.
Paste this code and run this
Below is screen shots:

sharepoint 2010 get all timer jobs powershell
sharepoint 2010 get all timer jobs powershell

And the output report:

sharepoint 2013 powershell get timer job history
sharepoint 2013 powershell get timer job history

Hope this will be helpful.


You May Also like the Following SharePoint Online Tutorials:

Leave a Reply