How To Restart timer service on all servers in farm

[array]$servers= Get-SPServer | ? {$_.Role -eq "Application"}            
$farm = Get-SPFarm            
foreach ($server in $servers)            
{            
    Write-Host "Restarting Timer Job on $server"                                      
    $Service = Get-WmiObject -Computer $server.name Win32_Service -Filter "Name='SPTimerV4'"                        
    if ($Service -ne $null)                         
    {                             
        $Service.InvokeMethod('StopService',$null)            
        Start-Sleep -s 7            
        $service.InvokeMethod('StartService',$null)                             
        Start-Sleep -s 7            
        Write-Host "Timer Job successfully restarted on $server"                        
    }             
    else            
    {            
        write-host -ForegroundColor Yellow "Could not find SharePoint 2010 Timer Service on $server"            
    }            
}
原文地址:https://www.cnblogs.com/Bear-Study-Hard/p/5039102.html