This script shows how to re-start all the SharePoint Timer Service instances in a SharePoint farm. The script defines a function that uses the Get-SPFarm cmdlet to get the current farm. Once the farm is got, the function get all the Timer Services instances through the TimeService.Instances member. For each Timer  Service instance, the script simply stop and start the instances.

 

PowerShell
Editar script|Remove
############################################################################################################################################ 
# This script allows to re-start all the SharePoint Timer Service instances in a SharePoint Farm 
# Required Parameters: N/A 
############################################################################################################################################ 
 
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )  
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } 
 
$host.Runspace.ThreadOptions = "ReuseThread" 
 
# 
#Definition of the function that allows to re-start all the SharePoint Timer Service instances in a SharePoint Farm 
function Re-StartSPTimerService 
{ 
    try 
    { 
        $spFarm=Get-SPFarm 
        $spfTimerServcicesInstances=$spFarm.TimerService.Instances 
        foreach ($spfTimerServiceInstance in  $spfTimerServcicesInstances) 
        { 
            Write-Host "Re-starting the instance " $spfTimerServiceInstance.TypeName 
            $spfTimerServiceInstance.Stop() 
            $spfTimerServiceInstance.Start() 
            Write-Host "SharePoint Timer Service Instance" $spfTimerServiceInstance.TypeName "Re-Started" 
        } 
    } 
    catch [System.Exception] 
    { 
        write-host -f red $_.Exception.ToString() 
    } 
} 
 
Start-SPAssignment –Global 
#Calling the function 
Re-StartSPTimerService 
Stop-SPAssignment –Global 
 
Remove-PSSnapin Microsoft.SharePoint.PowerShell