Microsoft Office Sharepoint

All my posts are provided "AS IS" with no warranties, and confer no rights.

Warm-up script

 

So , you are in need of a warm-up , and do not want to invest in writing and deploying a timer job as per http://msdn.microsoft.com/en-us/library/cc406686(office.12).aspx, or simply you want to keep things to a minimum …

Hmmm.

Here’s a PowerShell script to achieve what you want (the script will issue one request to your site, like you would do through IE):

$url = read-host -Prompt "Enter the URL to get ex http://www.contoso.com/default.aspx"
$wc = new-Object System.Net.WebClient
$httpRequest = [System.Net.HttpWebRequest]::Create($url)
$httpRequest.Credentials =[System.Net.CredentialCache]::DefaultCredentials
$httpRequest.UnsafeAuthenticatedConnectionSharing = "true"
$httpRequest.Method = "GET"
$httpRequest.Timeout = 300000
$objResponseReader = [System.IO.StreamReader]($httpRequest.GetResponse().GetResponseStream())
$httpResponse = $objResponseReader.ReadToEnd().ToString()

save this as WarmUp_One.ps1 and your’re all set. Whenever in need, you can run this and target it to an URL to your liking.

 

Now if you want to warm them all Smile, here’s the modified version for all your web applications.

 

add-pssnapin Microsoft.SharePoint.Powershell
$wc = new-Object System.Net.WebClient

function Warm_UP ([string]$url)
{
write-host("warming up  "+$url +"….")
$httpRequest = [System.Net.HttpWebRequest]::Create($url)
$httpRequest.Credentials =[System.Net.CredentialCache]::DefaultCredentials
$httpRequest.UnsafeAuthenticatedConnectionSharing = "true"
$httpRequest.Method = "GET"
$httpRequest.Timeout = 300000
    try
    {
    $responsecode = $httpRequest.GetResponse()
    $objResponseReader = [System.IO.StreamReader]($httpRequest.GetResponse().GetResponseStream())
    $httpResponse = $objResponseReader.ReadToEnd().ToString()
    Write-Host ($reponsecode.StatusCode)
    }
    catch
    {
     Write-Host("Error")
    }
}

get-spwebapplication | Foreach-Object {Warm_UP($_.Url)}
write-host("all warm and fuzzy inside :)")

Save this as WarmUp_All.ps1 and execute it in PowerShell, or schedule it to run with task manager

 

Technical details on the functions used:

http://technet.microsoft.com/en-us/library/system.net.httpwebrequest.aspx