Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Apr 25, 2015

will it be able to check correctly?

@djadjabing

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.