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.
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
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
Hi Anthony.
One option is to run the script as a scheduled Task in Windows Task Manager. Hope this helps.
Brgd Bjorn