Saturday, July 30, 2016

Start all enabled timer jobs on a SharePoint 2010 farm using PowerShell and check their status

Get-SPTimerJob | where { $_.IsDisabled -eq $false } | sort $_.Name | ForEach-Object {
    try
    {  
        $timerJobName = $_.Name
        if ($_.WebApplication -ne $null) { $waMessage = "on web application $($_.WebApplication.Url)" }
        else { $waMessage = "on Farm" }
        Start-SPTimerJob -Identity $_
        Write-Host "Started timer job $timerJobName $waMessage"
    }
    catch
    {
        Write-Host "There was a problem starting timer job $timerjobName:" $_
    }
}


if you want to have report of current status of each timer job in the output file, then run the script


function Get-SPTimerJobStatus
{
    Get-SPTimerJob | sort Name | ForEach-Object

{
        $lastRun = $_.HistoryEntries | Select-Object -first 1
        if ($_.WebApplication -eq $null) { $level = "Farm" }
        else { $level = $_.WebApplication.Url }
       
        $values = @{
            "Name" = $_.Name
            "Level" = $level
            "StartTime" = $lastRun.StartTime
            "EndTime" = $lastRun.EndTime
            "Status" = $lastRun.Status
        }

        New-Object PSObject -Property $values | Select @("Name","Level","StartTime","EndTime","Status")

    }

}

Get-SPTimerJobStatus | Out-GridView










No comments:

Post a Comment