SharePoint 2013 Warm-Up Script

Original posting can be found here

A Warm-Up Script is essential for seldom used pre-production environments to avoid waiting for what seems like an eternity for the web applications to warm up.  For the past couple of years I have been using a warm-up script written by Ryan Dennis, who in turn based his script off one from Kirk Hofer.  The script worked great in my SharePoint 2010 farms, but had issues with our new 2013 farm.  The problem was the script could no longer return the default credentials (account the script is executed under), so I updated it to use the Invoke-WebRequest cmdlet after reading a blog post from Todd Klindt.

The script will iterate through all the Site Collections in each of the Web Applications as well as open any sites located in the warmup-extrasites.txt file.  I use this file to open Office Web App documents, access my ADFS server, as well as keeping SSRS servers active.

############################################################################
#WarmUpScriptV2.ps1 - Enumerates all site collections in each web applications
# for a 2013 SharePoint farm using the Invoke-WebRequest cmdlet using the default credentials.
#
# Script will also cycle through any sites in the $extrasitelistfile. For example I use it to
# warm up the OWA 2013 servers by passing it the WopiFrame.aspx page with parameters to open a
# PowerPoint, Word, and Excel document out of a SharePoint document library.
#
#Notes:
# Script was developed using a combination of information from Ryan Dennis, Kirk Hofer's and Todd Klindt's Blogs:
# http://kirkhofer.wordpress.com/2008/10/18/sharepoint-warm-up-script/
# http://sharepointryan.com/2011/03/29/warming-up-sharepoint-2010-using-powershell/
# http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=404
#
#Assumptions:
#
#Running on machine with SharePoint 2013 installed
############################################################################
 
cls
 
Add-PsSnapin Microsoft.SharePoint.PowerShell
$extrasitelistfile = 'D:\Scripts\SharePoint\WarmUp\warmup-extrasites.txt'
 
Start-SPAssignment -Global
 
# Iterates through the sites in each web application
 
$apps = get-spwebapplication -includecentraladministration
foreach ($app in $apps) {
	$sites = get-spsite -webapplication $app.url -Limit ALL
	foreach ($site in $sites) {
		write-host $site.Url;
		$r = Invoke-WebRequest -URI $site.Url -UseDefaultCredentials
		$r.StatusCode
	}
}
 
# Warm up other sites specified in warmup-extrasites.txt file (such as SSRS)
 
if (test-path $extrasitelistfile) {
	$extrasites = get-content $extrasitelistfile
	foreach ($site in $extrasites) {
		write-host $site;
		$html=Invoke-WebRequest -Uri $site -UseDefaultCredentials
	}
}
 
Stop-SPAssignment -Global

SharePoint 2013 Warm-Up Script | SharePoint Observations

In my example I have placed a copy of the Script and the warmup-extrasites.txt file in the D:\Scripts\SharePoint\WarmUp directory.  This is just a text file with a URL on each line and will look something like this:

SharePoint 2013 Warm-Up Script | SharePoint Observations

The script requires no parameters and can be executed directly from a PowerShell cmd or ISE window:

SharePoint 2013 Warm-Up Script | SharePoint Observations

Now that we’ve successfully tested the script the next step is to create a scheduled task and will run after start up and execute on a regular interval throughout the day.

The first step is to create a task in the Task Scheduler:

SharePoint 2013 Warm-Up Script | SharePoint Observations

Fill out each of the tabs as follows:

SharePoint 2013 Warm-Up Script | SharePoint Observations

In the Actions tab we’ll point to the PowerShell executable and add the path of the script as the argument:

  • Script path: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  • Arguments: D:\Scripts\SharePoint\WarmUp\WarmUpScript.ps1

SharePoint 2013 Warm-Up Script | SharePoint Observations

You can click “OK” leaving the other settings at the default to complete creating the task and provide the credentials for the task to run under.  Keep in mind the account needs access to all the site collections as well as permissions to execute a scheduled task on the server.

Now that the task has been created manually execute it and verify a successful completion.