Warm-up Script for Web Front End Servers (WFE) in Load Balanced SharePoint Farms

There are many PowerShell scripts available to warm up SharePoint environments but they do not all handle "warming-up" multiple WFE Servers.

Below is a combination of a few scripts I found:

One from Bram http://bramnuyts.be/tag/warmup-script/

and one from Todd http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=404 which makes use of the new V3 PowerShell changes but does not cater for a Load Balancer unless you edit the Hosts file on the server to point to itself.

 

The below script should be scheduled after your app pools have recycled and should be setup through a windows task schedule and must be run as a User that has at least Read access to all Site Collections.

Make sure the DisableLoopbackCheck is configured as per Method 1 http://support2.microsoft.com/kb/896861 on production environments or one of my posts http://blogs.technet.com/b/scottstewart/archive/2014/09/15/disableloopbackcheck-when-routing-through-a-load-balancer-powershell-sample-included.aspx

 

I suggest either creating an account and adding the User to each Web App User Policy or make sure your Site Collection Admin has access to each Site Collection.

STEPS

  1. OPEN POWERSHELL ISE OR POWERSHELL AS A FARM ADMIN
  2. COPY AND PASTE THE POWERSHELL BELOW (Between the "#--------------------------")
  3. TEST THE SCRIPT TO ENSURE NO ERRORS OCCUR
  4. SAVE THE FILE AS A .PS1 TYPE IN A DESIGNATED LOCATION e.g. c:\powershell\warmupscript.ps1
  5. SCHEDULE A WINDOWS TASK TO RUN AFTER THE LAST APPLICATION POOL IS RECYCLED (4am should be safe)

 

## PowerShell Starts here

#--------------------------------------------------

Add-PsSnapin Microsoft.SharePoint.PowerShell -erroraction silentlycontinue
  
 function get-webpage([string]$url,[System.Net.NetworkCredential]$cred=$null)
 {
   $bypassonlocal = $false
   $proxyuri = "http://" + $env:COMPUTERNAME
   $proxy = New-Object system.Net.WebProxy($proxyuri, $bypassonlocal)
   $wc = new-object net.webclient
   $wc.Proxy = $proxy
   if($cred -eq $null)
   {
     $cred = [System.Net.CredentialCache]::DefaultCredentials;
   }
    
   $wc.credentials = $cred;
   return $wc.DownloadString($url);
 }
 
 $cred = [System.Net.CredentialCache]::DefaultCredentials;

## This can be used if required to force using certain credentials
 #$cred = new-object System.Net.NetworkCredential("username","password","machinename")
 
#Get the Web Apps
 $apps = get-spwebapplication # -includecentraladministration (Central admin is not included as it is not running on my WFE Server)
 
 foreach ($app in $apps) {
   #Get the Site Collections
   $sites = get-spsite -webapplication $app.url -Limit All
  
   ### UNCOMMENT THE 2 LINES BELOW IF YOU ONLY WANT TO USE THIS AT SITE COLLECTION LEVEL - Not required if Sites are warmed up.
   #write-host $app.Url;
   #$html=get-webpage -url $app.Url -cred $cred;

  
   ###COMMENT OUT BETWEEN THE "=======" IF THERE ARE TOO MANY WEBs i.e. Sites and you don't want to warm them up.
   #==================
    foreach ($site in $sites) {
      foreach ($web in $site.AllWebs) {
      #get the webs i.e. Sites
          write-host $web.Url;
          $html=get-webpage -url $web.Url -cred $cred;
     }
    }
    #=================
 }

#--------------------------