Pages

Search This Blog

Friday, January 4, 2013

Reset IIS on all the servers in FARM



Save the commands in a power shell script file and execute it in any of the servers present in FARM.



Write-Host -foregroundcolor Green "Restarting IIS on all the servers in FARM..."

[void][reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint")
[void][reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration")
[void][reflection.assembly]::LoadWithPartialName("System")
[void][reflection.assembly]::LoadWithPartialName("System.Collections")
# Get the local farm instance

[Microsoft.SharePoint.Administration.SPFarm]$farm = [Microsoft.SharePoint.Administration.SPFarm]::get_Local()

#Step through each server in the array and perform an IISRESET
#Also show IIS service status after the reset has completed

foreach ($server in $farm.Servers)
{
    if($server.Role -ne "Invalid")
    {
       Write-Host -foregroundcolor White ""
       Write-Host -foregroundcolor Yellow "Restarting IIS on server $server..."
       IISRESET $server.Name /noforce
       Write-Host -foregroundcolor Yellow "IIS status for server $server"
       IISRESET $server.Name /status
    }
}
Write-Host Write-Host -foregroundcolor Green IIS has been restarted on all servers
Read-Host 'Done...'



No comments:

Post a Comment