Skip to content

Instantly share code, notes, and snippets.

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:
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 = ''
[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

This comment has been minimized.

Copy link

pannu0786 commented Apr 25, 2015

will it be able to check correctly?


This comment has been minimized.

Copy link

djadjabing 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?


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.