This PowerShell SharePoint tutorial, we will discuss how to get the SharePoint timer job history using PowerShell as well as from SharePoint 2013/2016 central administration.
Recently, I got a requirement to retrieve and review the SharePoint timer job history for troubleshooting an issue in SharePoint 2013 farm.
SharePoint Tutorial Contents
SharePoint 2013/2016 Central Administration site provides an interface to review timer job history. Here are the steps to get a SharePoint timer job history in SharePoint.
Open SharePoint central administration, Go to Monitoring -> Check Job status.
Click on the “Job History” link from the left navigation.
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.
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.
Click on the job definition filter to “change job definition“.
Pick the relevant timer job definition. E.g. Audit Log Trimming, Immediate Alerts, etc.
Now, you’ll find the job history for the selected timer job as below.
Now, we will check how to search and export timer job history for a particular time period using PowerShell.
Why PowerShell? Well, the above central admin page provides the interface to analyze timer jobs associated with a 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 a PowerShell script to find and extract timer job history.
Below is the PowerShell script to get all the timer jobs of a web application in SharePoint 2013/2016.
Here, you just need to change the web application URL and then you can use the code inside Windows PowerShell ISE.
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
Below is the PowerShell script to get the failed timer jobs history report using PowerShell in SharePoint 2013/2016.
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
Below screenshot:
And the output report:
You may like following SharePoint tutorials:
- How to debug custom web part and timer job in SharePoint 2013 using Visual Studio
- Create Azure WebJobs for SharePoint Online and Deploy to Microsoft Azure
- User Information List in SharePoint 2016/2013/2010
- Content type HUB SharePoint 2013 Tutorial
- SPUtility.js SharePoint 2013 tutorial and Examples
- Force Retention Policy to Run Now or specific Days in SharePoint 2013
- Create remote event receiver SharePoint Online Step by Step Tutorial
This SharePoint tutorial, we learned how to get SharePoint timer job history from central administration as well as by using PowerShell. We also saw, how to get the failed timer jobs history report using PowerShell in SharePoint 2013/2016.