Quantcast
Viewing latest article 9
Browse Latest Browse All 10

Viewing Timer Job History for a Specific Date and Time Period

Central Administration provides several ways to view timer job history for a SharePoint farm. From the Job History page, you can view by Service, Web Application, Server, Job Definition or Failed Jobs. This is a really useful resource when you’re analysing issues with a specific job or service. However, if you want to investigate by a particular time period then you don’t really have any options other than to click through page after page after page…

Image may be NSFW.
Clik here to view.
Timer Job History Options

Fortunately the job history is available to access through PowerShell. I found this TechNet forum post which pointed me in the right direction, and also a useful blog post and script by Dave Hancock. (Dave’s script looks like it does exactly what I needed but unfortunately I had issues getting it to run).

So, below is a script I’ve put together which I run in the Windows Integrated Scripting Environment to output a grid view of all timer jobs between two dates and times, for all web applications in the farm:

Update 19/12/2011: I’ve made a small modification (at the suggestion of Jaap Vossers) so that the script now lists any jobs that either start in the specified range, or end in the specified range.

cls
# Add SharePoint cmdlets reference
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

function Get-TimerJobs {
    param(
        [DateTime] $startTime,
        [DateTime] $endTime
    )

    Get-SPWebApplication | foreach {
        $_.JobHistoryEntries |
             where{ ($startTime -le $_.StartTime -and $_.StartTime -le $endTime) -or
                    ($startTime -le $_.EndTime -and $_.EndTime -le $endTime) } |
                sort StartTime |
                select JobDefinitionTitle,WebApplicationName,ServerName,Status,StartTime,EndTime,@{Expression={($_.EndTime - $_.StartTime).TotalSeconds};Label="Duration (secs)"}
    }
}

$startDate = Get-Date "15/12/2011 11:00 AM"
$endDate = Get-Date "15/12/2011 11:50 AM"

$results = Get-TimerJobs -startTime $startDate -endTime $endDate
$results | Out-GridView

Which gives an output like the below (I’ve removed server name and web application name from the screenshot) from which I can easily spot if there are any failed jobs or jobs that took an unusually long time:
Image may be NSFW.
Clik here to view.
Timer Job History Capture


Viewing latest article 9
Browse Latest Browse All 10

Trending Articles