Skip to content

Instantly share code, notes, and snippets.

@leegould
Created December 10, 2012 14:18
Show Gist options
  • Save leegould/4250809 to your computer and use it in GitHub Desktop.
Save leegould/4250809 to your computer and use it in GitHub Desktop.
Cache warming script for pre iis 7.5
<#
.SYNOPSIS
This is a powershell script to ping a website and log the response
.DESCRIPTION
The script will send a web request to the site specified in the parameters, and log to the file specified in the parameters (if any)
.EXAMPLE
./api.warmup.ps1 -url http://api.mysite.com/ -logFile logfile.txt
.NOTES
logfile is optional.
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$url,
[Parameter(Mandatory=$False,Position=2)]
[string]$logFile
)
[net.httpWebRequest] $req = [net.webRequest]::create($url)
$req.Method = "HEAD"
[net.httpWebResponse] $res = $req.getResponse()
if ($logFile -ne "") {
$date = Get-Date
if ($res.StatusCode -ge "200") {
$date.ToString() + " : " + $url + " : Response OK" >> $logFile
} else {
$date.ToString() + " : " + $url + " : Response Error : " + $res.StatusCode + " " + $res.StatusDescription >> $logFile
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment