Skip to content

Instantly share code, notes, and snippets.

@ararog
Created November 5, 2013 10:35
Show Gist options
  • Save ararog/7317050 to your computer and use it in GitHub Desktop.
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/
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
}
@pannu0786
Copy link

will it be able to check correctly?

Copy link

ghost commented Aug 24, 2016

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