Run Warmup Script on Startup

Recently ran across a SharePoint install that had links to all the web apps in the Startup folder on the WFE box.  First thought was, PowerShell that mess!

First you will need to create a batch file to call the PowerShell warmup script.  The batch file will need to live in your Startup folder. By doing this, the script will run on server startup.

*update*  what if you want to pause / delay the batch file? Simply add a “timeout /t 5” after the @echo off statement.  *remove the quotes and 5 is measured in seconds.*

@echo off
timeout /t 5
powershell.exe d:\PowerShellScripts\warmup.ps1

The PowerShell warmup script:


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;
}

warmup script was created by Jon Badgett

http://www.jonthenerd.com/2011/04/19/easy-sharepoint-2010-warmup-script-using-powershell/