Pages

Thursday, January 27, 2011

SharePoint Warm up Scripts for WSS/MOSS

Normally all the Application Pools that get created are scheduled to reset themselves at a certain time usually around 1.45 AM in the morning. Therefore if you browse the web site for the time, it takes long time to load the web application but instead of using this script, it speed the web application.
So if you want this script, add the below code I have provided in a PS1 script and scheduled in windows scheduled task list. You can remove those app pool recycles that are scheduled
Save the following in a script named SharepointWarmUpscript.ps1 (1 is numeric value one).
Code:
iisreset
############################################################################
#Assumptions:
#-Running on machine with WSS/MOSS
#-C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN in path
############################################################################
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=stsadm -o enumzoneurls
foreach ($zone in $x.ZoneUrls.Collection) {
[xml]$sites=stsadm -o enumsites -url $zone.Default;
foreach ($site in $sites.Sites.Site) {
write-host $site.Url;
$html=get-webpage -url $site.Url -cred $cred;
}
}
Then go to the windows scheduled task, add new task and scheduled when you want and run it.
You can understand the difference between default scheduled recycling and the warm up script.
clip_image002