Sunday 17 November 2013

Powershell to restart timer service in Multitier SharePoint Farm

The SharePoint Timer service



As a single unified logical entity, a SharePoint farm requires a mechanism to run tasks necessary to provide its services. These tasks include updating components of the farm such as servers and services, and updating data and configuration in farm databases. To run these tasks, SharePoint provides its own scheduled tasks management service, manifested as Timer Service instances installed on every SharePoint server in the farm. If the Timer Service or any of its instances on servers begins to malfunction, it won't take long for problems to begin appearing across the farm. For all its importance, though, the Timer Service is often misunderstood. In this blog post we'll explore the basic elements and startup process of the SharePoint Timer Service. In the future and as time permits, we'll further explore the Timer Job system and many of the specific Timer Jobs which run in a farm.


Start the timer service:
  1. Verify that the user account that is performing this procedure is a member of the Administrators group on the local computer.
  2. Open a Command Prompt window, type the following command at the command prompt, and then press ENTER:
    net start sptimerv4
  3. If the service does not start, ensure that the service identity account is configured correctly by using the "Verify the service account" procedure later in this article.

Verify the service account:

  1. Verify that the user account that is performing this procedure is a member of the Administrators group on the local computer.
  2. Click Start, click Administrative Tools, and then click Services.
  3. Right-click Windows SharePoint Services Timer V4, and then click Properties.
  4. On the Log On tab, confirm that the account being used is a domain user account and is a member of the following:
    • dbcreator fixed SQL Server server role
    • securityadmin fixed SQL Server server role
    • db_owner fixed database role for all databases in the server farm
  5. If the account has sufficient permissions, confirm the password by typing the password for the account, retyping the password in the Confirm password box, and then clicking OK.
  6. Start the service by right-clicking the service name in the Services console, and then clicking Start.

Set Timer job status Online in Multiserver Farm:

$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"

}


Timer job restart in Multiserver farm:

Use powershell script to restart timer services of all servers in a farm. Run below script in any server of a farm.

$farm = Get-SPFarm

$farm.TimerService.Instances | foreach {$_.Stop();$_.Start();}



You can get this job done in more interactive way by running below bunch of lines in SharePoint Management Shell


[array]$servers= Get-SPServer | ? {$_.Role -eq "Application"}
foreach ($server in $servers)
{
    Write-Host "Restarting Timer Service on $server"
    $Service = Get-WmiObject -Computer $server.name Win32_Service -Filter "Name='SPTimerV4'"
    if ($Service -ne $null)
    {
        $Service.InvokeMethod('StopService',$null)
        Start-Sleep -s 8
        $service.InvokeMethod('StartService',$null)
        Start-Sleep -s 5
        Write-Host -ForegroundColor Green "Timer Job successfully restarted on $server"
    }
    else
    { 
        Write-Host -ForegroundColor Red "Could not find SharePoint Timer Service on $server"
    }
}


No comments:

Post a Comment