Warmup that farm

[Update: 23/02/10] I have updated this script in a new post here which does not rely on STSADM and therefore does not need to be run as admin.

With all the 2010 lab testing I have been doing lately I’ve been meaning to get around to creating / finding a new WarmUp script to use but this time based on PowerShell.

What I found is fortunately there are loads of examples out there to get you started as with most things PowerShell. See Kirk Hofer’s Blog for the one I started with.

So anyway I have added a little to the script, now in addition to opening each site in the farm it also parses a text file (C:ToolsWarmupwarmup-extrasites.txt) for additional URL’s, which I use to warm up particular SSRS or Excel reports.

Warmup.ps1

############################################################################
#Assumptions:
#-Running on machine with WSS/MOSS
############################################################################
 
$stsadmexe = 'C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12BINSTSADM.exe'
$extrasitelistfile = 'c:ToolsWarmupwarmup-extrasites.txt'
 
function get-webpage([string]$url,[System.Net.NetworkCredential]$cred=$null)
{
  $wc = new-object net.webclient
  if($cred -eq $null)
  {
    $cred = [System.Net.CredentialCache]::DefaultCredentials;
  }
  $wc.credentials = $cred;
  return $wc.DownloadString($url);
}
 
#This passes in the default credentials needed. If you need specific
#stuff you can use something else to elevate basically the permissions.
#Or run this task as a user that has a Policy above all the Web
#Applications with the correct permissions
 
$cred = [System.Net.CredentialCache]::DefaultCredentials;
#$cred = new-object System.Net.NetworkCredential("username","password","machinename")
 
[xml]$x=&$stsadmexe -o enumzoneurls
foreach ($zone in $x.ZoneUrls.Collection) {
  [xml]$sites=&$stsadmexe -o enumsites -url $zone.Default;
  foreach ($site in $sites.Sites.Site) {
    write-host $site.Url;
    $html=get-webpage -url $site.Url -cred $cred;
  }
}
 
# Warm up other sites specified in warmup-extrasites.txt file (such as SSRS)
 
if (test-path $extrasitelistfile) {
  $extrasites = get-content $extrasitelistfile
  foreach ($site in $extrasites) {
    write-host $site;
    $html=get-webpage -url $site -cred $cred;
  }
}

Warmup-ExtraSites.txt
http://servername/ReportServer

Download both files here.

Take note of the variables at the top of the script with the paths pointing to the 14 hive and the extra sites text file.

Save those files somewhere (default c:ToolsWarmUp) then schedule them to run with a command line as follows:
C:WindowsSystem32WindowsPowerShellv1.0powershell.exe C:ToolsWarmupwarmup.ps1

Finally just make sure you select the Run with highest privileges option as stsadm will need that to enumerate the sites.

Enjoy!

Share and Enjoy !

Shares