SharePoint Shell to restart IIS and Timer services on Farm

To restart IIS on a SharePoint 2010 Farm

Save the below in to *.ps1 file

cls
Write-Host “Loading SharePoint Commandlets”
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
Write-Host -ForegroundColor Green ” Commandlets Loaded … Loading Variables”
Write-Host
[array]$servers= Get-SPServer | ? {$_.Role -eq “Application”}
$farm = Get-SPFarm
foreach ($server in $servers)
{
Write-Host -ForegroundColor Yellow “Attempting to reset IIS for $server”
iisreset $server /noforce “\\”$_.Address
iisreset $server /status “\\”$_.Address
Write-Host
Write-Host -ForegroundColor Green “IIS has been reset for $server”
Write-Host
}
Start-Sleep -Seconds 5
Write-host

Depending on the size of your farm increase the sleep time

 

Restart of Timer services in SharePoint 2010

Write-Host “Restarting SharePoint Timer service on each server in the farm” -ForegroundColor Blue
[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” -ForegroundColor Green
}
else
{
write-host “Could not find SharePoint 2010 Timer Service on $server” -ForegroundColor Red
}
}

Write-Host “Script execution complete!” -ForegroundColor White -BackgroundColor Green

 

Comments

comments

Privacy Preference Center