Retrieve timer job history for a specified time range using PowerShell


 

 

# Retrieve timer job history for a specified time range

# Initial settings

$Wa = Get-SPWebApplication "http://WebAppUrl"    # Supply the web app url here

$From= "2/13/2013 12:00:00 AM# mm/dd/yyyy hh:mm:ss

$To = "2/14/2013 12:00:00 AM"

# Retrieve all jobs in the time range

Write-Host "Listing all timer jobs that have run between $From to $To and storing it in CSV format" -ForeGroundColor
Blue

$Wa.JobHistoryEntries | Where-Object {($_.StartTime -gt $From) -and ($_.StartTime -lt $To)} | Export-Csv TimerJobHistory.csv –NoType

Write-Host "Done.." -ForeGroundColor Green

# Retrieve all failed jobs in the time range

Write-Host "Listing all timer jobs that have failed to run between $From to $To and storing it in CSV format" -ForeGroundColor Red

$Wa.JobHistoryEntries | Where-Object {($_.StartTime -gt $From) -and ($_.To -lt $To) -and ($_.Status -neSucceeded‘)} | Export-Csv FailedTimerJobHistory.csv –NoType

Write-Host "Done.." -ForeGroundColor Green

 

Comments (8)

  1. Praveen Hebbar says:

    hi Jan,

    You could use:

    Get-SPTimerJob | % { $_.HistoryEntries } | Where-Object {($_.StartTime –gt “MM/DD/YYYY hh:mm:ss”) -and ($_.EndTime -lt “MM/DD/YYYY hh:mm:ss AM”) } | Format-Table –Property StartTime,EndTime,JobDefinitionTitle

  2. Anonymous says:

    Great script

  3. Raj says:

    Does it work for Content Deployment jobs too?

  4. Jan Egil Kristiansen says:

    But not all jobs are connected to web applications. How can I use PowerShell to see their history?

  5. RedK says:

    How do I tell it where to store the file? I ran the script but can’t find the file anywhere

  6. RedK says:

    Nevermind!

  7. rajeev says:

    RedK- Just mention the path after export command c:FailedTimerJobHistory.csv or by default it will be stored in current path u r running script.

  8. Adrian Gonzalez says:

    Thank you so Much, very helpful