SharePoint Server 2010: Timer Jobs not Functioning After Applying Updates

[ Updated 10/28/2011]: Changing the title of the post . This problem affects several areas of the product, not just profile synchronization

Overview

I recently came across a nasty case where the user profile synchronization service just won’t start. Additionally, the one-time timer jobs that are created as a result of certain administrative operations were not getting deleted.  The problem started happening after the SharePoint environment was patched and upgraded with a cumulative update.  It all boiled down to the timer service instance object on some of the servers being in an Offline state (even though the Windows Timer Service was started).  Here are the details of the problem and the solution:

Note: User Profile Synchronization service can fail to start in several different scenarios, this post talks about the scenario where the timer service instance object is left in an Offline state on one or more servers, which is likely to happen after an upgrade. The Power Shell commands provided in the article below can help you confirm whether or not you’re running into the problem of offline timer service instance.

The Timer Service Instance Object (SPTimerServiceInstance)

Every SharePoint server has one SPTimerServiceInstance object which basically represents the SPTimerV4 Windows Service. In certain circumstances (typically after an upgrade), you could end up in a situation where your timer service is running on the server but the SPTimerSericeInstance object is not Online. In this case, any administrative operations that depend on timer jobs to be completed  (such as starting the User Profile Synchronization Service) will not be successful.

Finding and Resolving the Problem

I have put together a PowerShell script that can be run on any SharePoint server in the farm. The script detects SPTimerServiceInstance objects in the farm that are not online, and attempts to update their status to Online.  After running the script, please manually restart the SPTimerV4 Windows Service (SharePoint 2010 Timer) on each server that is identified to have the problem.

$farm = Get-SPFarm
$disabledTimers = $farm.TimerService.Instances | where {$_.Status -ne "Online"}
if ($disabledTimers -ne $null)
{
foreach ($timer in $disabledTimers)
{
Write-Host "Timer service instance on server " $timer.Server.Name " is not Online. Current status:" $timer.Status
Write-Host "Attempting to set the status of the service instance to online"
$timer.Status = [Microsoft.SharePoint.Administration.SPObjectStatus]::Online
$timer.Update()
}
}
else
{
Write-Host "All Timer Service Instances in the farm are online! No problems found"
}

Hope you find this useful!

Happy SharePointing!