Created
December 10, 2012 14:18
-
-
Save leegould/4250809 to your computer and use it in GitHub Desktop.
Cache warming script for pre iis 7.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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