How to do an IISReset in all the servers in a SharePoint Farm?

This SharePoint PowerShell tutorial, we will discuss how to do IISRESET in all the servers in the SharePoint 2013/2016 farm. This script allows doing an IIS Reset to all the servers (Web Front End and Application Servers) in a SharePoint farm (SharePoint 2010 and SharePoint 2013 SharePoint versions). The script defines a function that uses the Get-SPServer cmdlet in order to get all the servers where the IISReset operation.

We use it when we want to perform an IISRESET across an entire SharePoint farm. It’s useful if you have a large SharePoint farm. This will take down your farm while the IISRESET is restarting the services, so it’s best to test this on a non-production environment first. Ensure you have an outage/agreed maintenance window to perform this task on a production farm.

All you got to do is spin up PowerShell on any SharePoint server in the farm and run the below PowerShell Script. You can use PowerShell ISE or Visual studio code to write, run, test and debug PowerShell script.

IISReset in all the servers in a SharePoint Farm

Below is the PowerShell script to do IISReset in all the servers in a SharePoint 2013/2016 Farm.

# This Scrip allows to do an IIS RESET to all the servers in a SharePoint Farm
# requited 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 funcion that performs the IIS RESET in all the servers
function Do-IISReset
{
try
{
#Getting the servers where the IISReset is going to be done
$spServers= Get-SPServer | ? {$_.Role -eq “Application”}
foreach ($spServer in $spServers)
{
Write-Host “Doing IIS Reset in server $spServer” -f blue
iisreset $spServer /noforce “\\”$_.Address
iisreset $spServer /status “\\”$_.Address
}
Write-Host “IIS Reset completed successfully!!” -f blue
}

catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}
Start-SPAssignment –Global

#Calling the function
Do-IISReset
Stop-SPAssignment –Global
Remove-PSSnapin Microsoft.SharePoint.PowerShell

You may like following PowerShell SharePoint tutorials:

Here, we learned how to do an IISReset in all the servers in a SharePoint 2013/2016 Farm.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>