SharePoint 2010 Wake Up Script as a Scheduled Task

So an Executive VP or Manager is the first person in the office in the morning, and ask you "Why is the intranet so slow every the morning?"

Well, IIS recycles daily at about 2:00am each night. This means that the first user request to access any SharePoint 2010 site will have to wait until the site "warms up" or "wakes up" before loading the page.

Lets change that! Below is a handy Powershell script that will query each top level site collection and send a request to the site. Lets take this Powershell script and combine it with a Windows scheduled task on the SharePoint web front end server(s). Lets start with the script:

//--Powershell Script Begin--

Add-PSSnapin Microsoft.SharePoint.PowerShell;

function Get-WebPage([string]$url)
{
$wc = new-object net.webclient;
$wc.credentials = [System.Net.CredentialCache]::DefaultCredentials;
$pageContents = $wc.DownloadString($url);
$wc.Dispose();
return $pageContents;
}

Get-SPAlternateUrl -Zone Default | foreach-object {
write-host $_.IncomingUrl;
$html = Get-WebPage -url $_.IncomingUrl;
}
//--Powershell Script End--

Step by Step Configuration

  1. Copy the Powershell script text above and save it as SharePointSiteWakeUp.ps1 on each of your SharePoint 2010 Web front end servers. Save the file in the "C:\Windows\" directory. 
  2. Next we will schedule a Windows Scheduled Task to run the Powershell script daily at 5:00am. (You can specify anytime after 2:15am).
  3. On your SharePoint 2010 Web Front End server(s), click 'Start' > 'Administrative Tools' > 'Task Scheduler' as shown below:   
  4. Next, Right click on 'Task Scheduler' and click 'Create Basic Task' as show below:                                                    
  5. Enter a Name for the Task and click 'Next'
  6. Set the Task Frequency to Daily and click 'Next'
  7. Set the scheduled daily Start time to 5:00 AM every 1 day and click 'Next'
  8. Choose the Action 'Start a Program' and click 'Next'
  9. Next, in the 'program/script' text box enter the following: powershell -file "C:\Windows\SharePointSiteWakeUp.ps1" then click 'Next': 
  10. You will receive a message that arguments have been included in the Program text box. Click 'Yes' to continue:                                        
  11. Review the Task Summary and click 'Finish' to complete the wizard: 

That is it! Now when the first user of the day goes to open a SharePoint site, it will respond in just 1-3 seconds instead of 30-45 seconds.