Created
November 5, 2013 10:35
-
-
Save ararog/7317050 to your computer and use it in GitHub Desktop.
A powershell script that can be used to check if a site is up and running, full description can be found at: http://faces.eti.br/2011/07/28/checking-website-status-with-powershell/
This file contains 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
function Show-MessageBox ($title, $msg) { | |
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null | |
[Windows.Forms.MessageBox]::Show($msg, $title, [Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Warning, [System.Windows.Forms.MessageBoxDefaultButton]::Button1, [System.Windows.Forms.MessageBoxOptions]::DefaultDesktopOnly) | Out-Null | |
} | |
[string] $url = 'http://www.saidosofa.com.br' | |
[net.httpWebRequest] $req = [net.webRequest]::create($url) | |
$req.Method = "HEAD" | |
[net.httpWebResponse] $res = $req.getResponse() | |
if ($res.StatusCode -ge "200") { | |
write-host "`nSite up`n" ` | |
-foregroundcolor green | |
} | |
else { | |
Show-MessageBox -title "Warning!" -msg "Site down!!!" | |
write-host "`nSite down`n" ` | |
-foregroundcolor red | |
} |
Hey may you can help me, I used this script, but when I check a page where I knew it's down, I'll get an Exception but why?
Exception calling "GetResponse" with "0" argument(s): "The underlying connection was closed: An unexpected error occurred on a receive."
- $HTTP_Response = $HTTP_Request.GetResponse <<<< ()
- CategoryInfo : NotSpecified: (:) [], MethodInvocationException
- FullyQualifiedErrorId : DotNetMethodException
How can I solved it?
Thanks
Cheers
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
will it be able to check correctly?