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:
$caUrl = "http://servername:5555"
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… >
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.
Set to run Daily and repeat every 10 minutes or so. I like to ensure that the sites are fresh more often.
Select the warm up batch file that you just created.
Finally set the account that will run the scheduled task. I would use the SharePoint System Account
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
"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.
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.
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.
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
Thanks for taking the time to post this and for your comments - very nice having those screen shots too