PowerShell to export timer job history in SharePoint

Published by Shubham Bansal on

SharePoint has a lot of out of the box timer jobs which keeps running every minute and then you deploy some timer job as part of your client’s requirement. Here is the PowerShell script which will export the history of the timer jobs you specify. You can get the job history within a particular time interval.

# Date and Time format to be used : mm/dd/yyyy hh:mm:ss

[code language="powershell"]
$From= "5/24/2017 9:00 PM"

$To = "5/24/2017 11:00 PM"
 # Array of the timer job you need the history for

$Jobs = @("TimerJobA”, “TimerJobB”, “TimerJobC”)
 # Get the timer job object for the ones we need

$TimerJobs = Get-SPTimerJob | ?{$_.Name -in $Jobs}
 ForEach($TimerJob in $TimerJobs)

{

ForEach($Entry in $TimerJob.HistoryEntries)
 {
 If(($Entry.StartTime -ge $From) -and ($Entry.EndTime -le $To))
 {
 $Entry.JobDefinitionTitle +","+ $Entry.Status +","+ $Entry.EndTime +","+ $Entry.StartTime +","+ $Entry.ErrorMessage| Out-File -FilePath "TimerJobHistory.csv" -Append
 }
 }
 }

[/code]

 5,335 total views,  2 views today

Care to Share?

0 Comments

Leave a Reply