IISRESET whole SharePoint farm

Posted: June 26, 2014 in SharePoint PowerShell
Tags:

Sometimes when you make big changes in SharePoint, you would like to do an IISRESET on all the SharePoint Servers, an easy way to do that is by using a PowerShell script.

Instructions:

  • Copy code into a text file and save as IISRESET_All.ps1
  • Run the script with your SharePoint install account, or any farmaccount
    that has local admin access to the SharePoint Servers.

 File:
newdl

Code:


<#====================================================================
 Copyright © 2014, january. Bjørn Roalkvam
 www.SharePointbjorn.com, bjorn80@gmail.com 

 Description:

 Do an iisreset and warmup on all SharePoint Servers.


 Always test all scripts you find in an test environment prior to production:-), 
 you are a responsible SharePoint Administrator afterall!
====================================================================#>

# ===================================================================================
#Checks whether the script is running as admin, if not then starts as admin.
# ===================================================================================
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))

{ 
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}

#Add sharepoint pssnapin if it doesnt exist:
if ( (Get-PSSnapin -Name microsoft.sharepoint.powershell -EA "SilentlyContinue") -eq $null )
{
 Add-PsSnapin microsoft.sharepoint.powershell
}

cls

#Filter SharePoint servers to avoid SQL Server
$AllSPServers = get-spserver | ? { $_.Role -eq "Application"}

#On all SP servers do an iisreset!
foreach ($SPServer in $AllSPServers)
{
$servername = $SPServer.name
Write-Host -f Cyan "Resetting $servername.."
iisreset $server
Write-Host ""
}

Write-Host ""
#Fast warmup
Write-Host -f Cyan "Quick warmup.."
$Wholethang = Get-spwebapplication -includecentraladministration | % {Get-spsite -webapplication $_.url -Limit ALL | % {write-host $_.Url; Invoke-WebRequest -URI $_.Url -UseDefaultCredentials }}

Write-Host -f Green "Completed.. window autoclose in 3 seconds"
sleep 3
exit

Advertisements
Comments
  1. Anthony Nwankwo says:

    Thanks Bjorn,

    Is it possible to have this script run as a scheduled job to clear our SharePoint site?

    We have a SharePoint site that is used massively as a Workflows platform.
    After about a week or less, the Windows Workflow Foundation (WWF) of the server will become very slow and will start queueing the workflows it is supported to process immediately.

    The only workaround we have always applied is to run ‘iisreset’. So it will be nice if we could have the script automated to run at intervals and pro-actively run the iisreset on the server.

    I appreciate your efforts.

    Best Regards,

    Anthony

  2. bjorn80 says:

    Hi Anthony.
    One option is to run the script as a scheduled Task in Windows Task Manager. Hope this helps.

    Brgd Bjorn

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s