Warm up script for Sharepoint sites

If you are preparing for a Demo or labs and just restarted your VM or performed a deployment and would like to make sure that your sites loads quickly for end users you must have the below script.  this script will allow you to warm up your site and will result in happy customers and may result in less “Man SharePoint is slow” thing.

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); 
} # end Function 
#This passes in the default credentials needed. You can run this task as a user that has a Policy  
# above all the Web Applications by manually adding the correct permissions 
$cred = [System.Net.CredentialCache]::DefaultCredentials; 
# or 
#$cred = new-object System.Net.NetworkCredential("username","password","machinename") 
#Change these URL's to suit your environment. Simply add more lines if you need more. 
$html = Get-WebPage -url "http://intranet.contoso.com/" -cred $cred 
$html = Get-WebPage -url "http://intranet.contoso/" -cred $cred
#Repeat for every site collection  

Note: Best thins would be to put this script in Task Schedular and enable it to run it daily at 7 AM.  Mostly App pool recyles happens early morning so your sites will be fresh when first user hits it.