Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's SharePoint Admin Blog > Posts > Using PowerShell to warm up SharePoint 2013
April 15
Using PowerShell to warm up SharePoint 2013

It’s an age old problem, our SharePoint app pools recycle every night, or they get cranky. But because they recycle every night the first person to hit SharePoint each morning has to wait for the app pools to warm back up, which makes them cranky. All that crankiness makes me cranky. Over the years a variety of startup scripts have been written to address this, and they all work to varying degrees.

SharePoint 2013 requires PowerShell v3, and it comes with a bunch of new cmdlets. One of them jumped out at me, Invoke-WebRequest. This cmdlet can be used to download files from web sites, like WGET or CURL. The beauty of Invoke-WebRequest is that it’s built in to every SharePoint 2013 server. While it was built to download files, it can also be used to make general web requests, like to SharePoint sites. You know, to warm up their app pools. Smile

Since it’s PowerShell, it scripts like a dream. The following script will request the default page of the root site collection of each web application in your farm:

Get-SPWebApplication | ForEach-Object { Invoke-WebRequest $_.url -UseDefaultCredentials -UseBasicParsing }

The –UseDefaultCredentials parameter tells Invoke-WebRequest to log in to the web site as the person that PowerShell is running as. –UseBasicParsing tells Invoke-WebRequest to use basic parsing of the web page. We really don’t care about the web page, we just want to wake SharePoint up to send it to us.

If you have multiple WFEs you’ll need to run this on each server. Also, different SharePoint web templates have different assemblies in the background. If the root site collection of a web application is based a Publishing Template any Team sites in that web app will still need to be warmed up. If you wanted to warm up one of each type you could send Invoke-WebRequest a list of site collection URLs instead of web applications, like above.

Once you get it all figured out, you can schedule your PowerShell script to run every morning before the work day starts. Scheduling PowerShell is a little tricky. You can use this blog post to create the scheduled task to warm up your app pools for you.

You’ll probably need to modify this for your environment, but hopefully it will get you started.

tk

ShortURL: http://www.toddklindt.com/PoshWarmUp

Comments

Only warms one WFE

Todd - Thanks for this.  It doesn't matter what WFE I run this on it only warms the same WFE (WFE1)  If I run it on WFE2 it will still warm WFE1 and not pre-warm IIS on WFE2.

Both WFE's work great in my farm so I don't think its a configuration issue.

Any ideas why?

Thanks

-CR
 on 4/19/2013 3:38 PM

Another question if I may..

While this seems to be working on my DEV farm, It does not seem to warm at all on my pre-production farm.  The main difference is the fact that I am using http//servername for my dev farm URL (pulled from Get-SPWebApplication) and https//AlternateDNS name from my pre-production farm.

Any thoughts on this issue?  Thanks and sorry for all the questions.

-CR
 on 4/19/2013 4:21 PM

Re: Only warms one WFE

Hey CR,
This is happening because your production SharePoint servers aren't pointing to themselves for SharePoint. See this blog post for an explanation of why you should do that, and how to fix it, http://www.toddklindt.com/edithosts

tk
Todd O. KlindtNo presence information on 4/19/2013 10:48 PM

What about SharePoint Online wave 15 ?

Hi Todd

How can this be achieved in SharePoint Online Wave 15 ?

Regards

Nigel
 on 4/22/2013 3:11 PM

Re: What about SharePoint Online wave 15 ?

It will and it won't. Invoke-WebRequest will work against any web server. That can be on-premises SharePoint, or a hosted Apache server with LOLCAT images on it. Invoke-WebRequest doesn't care. So in that regard, yes, it will work with SharePoint Online.

However, I'm sure SharePoint Online has a bunch of WFEs, and unless you know all of their IP addresses there's no way for you to fashion your Invoke-WebRequest command to hit them all. Your client will query DNS the first time and you'll only hit one IP after that. I also assume there's some fancy load balancer in the mix too.

So yes, Invoke-WebRequest will work against any web server, even SharePoint Online, but no, it probably won't work to warm up those app pools.

Hope that helped,
tk
Todd O. KlindtNo presence information on 4/23/2013 8:58 AM

Thank you

Todd,

Just wanted to thank you for the help.  It worked great and now I use Task Scheduler to warm up my site on boot as well as after AppPool recycling with the PS script.

Great site you have here.  It is now permanently bookmarked...

-CR
 on 4/23/2013 10:40 AM

Re: Thank you

You're very welcome. I'm glad it's working for you.

tk
Todd O. KlindtNo presence information on 4/24/2013 8:22 AM

Should this also warm all sites within the web app?

Todd,

Should this also warm all sites within the web app? It seems that root site loads much faster than other sites within the same app.  Maybe it is just me or I am missing something.

Any thoughts?

Thanks
-CR 
 on 4/24/2013 3:04 PM

Getting the following message - How to stop this script!

===============
PS C:\Users\xyz> Get-SPWebApplication | ForEach-Object { Invoke-WebReque
st $_.url -UseDefaultCredentials -UseBasicParsing }
Invoke-WebRequest : The remote server returned an error: (404) Not Found.
At line:1 char:41
+ Get-SPWebApplication | ForEach-Object { Invoke-WebRequest $_.url
-UseDefaultCred ...
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:Htt
   pWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe
   ll.Commands.InvokeWebRequestCommand
========================
 on 6/6/2013 2:54 AM

Re: Getting the following message - How to stop this script!

As we all learned in our very first day with a web browser, a 404 code means "not found." Sounds like you have a web application without a site collection at its root. If you browse to each URL returned by get-spwebapplication in a regular browser, what happens? You also ask how to stop script. It should stop quickly on its own. Otherwise you can stop it the same way you stop any PowerShell script by hitting Ctrl-C.

tk
Todd O. KlindtNo presence information on 6/9/2013 2:15 PM
1 - 10Next

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person

Twitter


Want a message when I reply to your comment? Put your Twitter handle here.

Attachments

 

 Please Support my Sponsors