MinimaList SharePoint WarmUp Script


In the spirit of Minimalism I have decided to create the simplest SharePoint warm up script that I could.  There are plenty of warm up scripts on the web.  Many of them are convoluted and difficult to manage.  This shouldn’t be that difficult.  All you need to do is enumerate your web applications and site collections.  Then make a simple web call to each of them using the correct credentials.  Once you have that all you need is a scheduled task to hit them on regular intervals. 

So here it is:

$wc = New-Object net.WebClient

$wc.Credentials = [System.Net.CredentialCache]::DefaultCredentials

Get-SPSite | ForEach {$wc.DownloadString($_.url)}

 

Bing! Simple right?

This will not hit the Central Administration site.  To do this  just add the following 2 lines.

$caUrl = “*http://servername:5555

$wc.DownloadString($caUrl)

 *Specify your specific central admin url.

______________________________________________________________________________________________________________

1. Create a PS1 file called warmup.ps1 and put these line in it:

$wc = New-Object net.WebClient

$wc.Credentials = [System.Net.CredentialCache]::DefaultCredentials

Get-SPSite | ForEach {$wc.DownloadString($_.url)}

$caUrl = “http://servername:5555

$wc.DownloadString($caUrl)

 

2. Create a batch file with this line in it:

 powershell -command “& ‘c:\warmup.ps1′”

 

3. Next you will need to setup a scheduled task.  Open Task Scheduler > Create New Task… >

embedded folder icon

 If you run this as hidden you will not see a popup.  Ensure that the task runs whether the user is logged on or not.

embedded folder icon

Set to run Daily and repeat every 10 minutes or so.  I like to ensure that the sites are fresh more often.

embedded folder icon

Select the warm up batch file that you just created.

embedded folder icon

Finally set the account that will run the scheduled task.  I would use the SharePoint System Account

embedded folder icon

______________________________________________________________________________________________________________

TESTING

On your SharePoint server temporarily change your Internet Explorer home pages to hit all of your site collections or at least web applications including Central Admin.

Test from a command line:

iisreset

powershell -command “& ‘c:\warmup.ps1′”

“C:\Program Files\Internet Explorer\iexplore.exe”

 You should see your sites load very quickly.  As always please test before you try this on your production farm.

Comments (6)

  1. A colleague of mine pointed out that in the warm up script the Get-SPSite is being used but the SharePoint module is not being declared. My bad 🙂

    You may need to add this line at the beginning of the script:

    Add-PsSnapin Microsoft.SharePoint.PowerShell

  2. Another point I realized later is that this will only pull up the default page of each Site Collection.  If you have custom pages that take time to load you may want to also add them to your script.  You can do this using the same method that the Central Administration site is added.

    $CustomPageUrl = "http://MyNameIsURL"

    $wc.DownloadString($CustomPageUrl)

    Customized or unghosted pages do not get compiled into a DLL and loaded into memory like ghosted pages.  Therefore they typically load faster than ghosted pages.  Sometimes that is not the case and adding them to the warm-up script may make the load time faster.

    If you haven't heard or read test everything you plan to do in Production should be TESTED on a non-Production QA environment before you do anything on your Production servers.  Your users deserve it.

  3. It was brought to my attention by a colleague of mine @ blogs.msdn.com/…/sharepoint_strategery that I did not mention that the PowerShell scripts need to be run locally on each SharePoint server.  My bad.  Thanks Brian – BTW you need to actually write a blog.

    For clarification running the PowerShell script locally will require that you modify the local HOSTS file on each server and add each web site base URL and IP address of the local server to ensure that you are hitting the local server rather than another server in the farm.

    Example

    127.0.0.1       localhost

    47.72.23.118   SharePointStrategery.com

    Further reading on HOSTS files:

    technet.microsoft.com/…/cc751132.aspx

    You really need to test, test, test, before you do this in Production.  Let's not be cowboy admins out there.

  4. Anonymous says:

    Un “problema” conocido en las distintas versiones de SharePoint es que los Application Pools de SharePoint

  5. Doug says:

    Thanks for taking the time to post this and for your comments – very nice having those screen shots too

  6. Leland Usher says:

    Robert, this is great, I have already seen a big improvement in my site render times. I have modified your script to add logging information as well. In my case management wanted to know how long the script ran etc. I will add my version here:

    #open logfile
    $logtime = (Get-Date -format s) -replace ":","_"
    $logfile = "c:scriptsWarmupScriptLog-" + $logtime + ".txt"
    $logstring = "`n" + "PowerShell Script starting at " + (Get-Date)
    Add-content $Logfile -value $logstring

    $wc = New-Object net.WebClient

    $wc.Credentials = [System.Net.CredentialCache]::DefaultCredentials

    Get-SPSite | ForEach {

    $wc.DownloadString($_.url)
    $logstring = "`n" + $wc.DownloadString($_.url)
    Add-content $Logfile -value $logstring
    }

    $caUrl = "http://yourcentraladmin"

    $wc.DownloadString($caUrl)

    #closeout log file
    $logtime = (Get-Date -format s) -replace ":","_"
    $logstring = "`n" + "Script completed at: " + $logtime
    Add-content $Logfile -value $logstring

    $wc.Dispose()

Skip to main content