• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

TECHDIIP

  • Tech
  • Windows
  • Powershell
  • Scripts
  • News
  • Games

Powershell script to test website status up or down on a local or remote computers

When there is a need to monitor the set of websites on the local computer or remote server computers it’s easy with a Powershell script, imagine if there are many remote computers one has to check manually then it’s quite difficult for administrators.

Here in this article, we explain how simple code can get any website status on local or remote computers.

$Website = [System.Net.WebRequest]::Create('https://techdiip.com')

# We then get a response from the site.
$HTTP_Response = $Website.GetResponse()

# We then get the HTTP code as an integer.
$HTTP_Status = [int]$HTTP_Response.StatusCode

If ($HTTP_Status -eq 200) {
    Write-Host "Site is Up and Working as expected!" -BackgroundColor Cyan
}
Else {
    Write-Host "The Site is down, please work on it!" -BackgroundColor Red
}

#  closing the Http request using the below code.

If ($HTTP_Response -eq $null) {
 } 
Else { $HTTP_Response.Close() }

Output of the script when the website is accessible.

powershell test website

If the website is not working it returns the output as “The Site is down, please work on it!” in the red color.

How to test website status on multiple remote computers.

We need to create a file for storing all the servers or multiple machines list, I named it as Allservers.txt for and saved it in my local machine c:\temp\Allservers.txt

$Allserers = get-content -path "C:\temp\Allservers.txt" 
$Url = "http://www.techdiip.com/"
foreach ($oneserver in $allservers) 
{
$website.StatusCode = $null
$website = Invoke-command $oneserver -Scriptblock{param($url)Invoke-WebRequest $url -UseBasicParsing | Select-Object statuscode } -ArgumentList $Url
if ($website.StatusCode -eq '200')
 Write-Host "Site is Up and Working as expected!" -BackgroundColor Cyan
}
Else {
    Write-Host "The Site is down, please work on it!" -BackgroundColor Red
}

}

The above script tests the website status on multiple remote computers, actually it test only status which means the website is accessible or not, make sure you have admin rights on the remote computers to run this script.

Thank you for reading this article, if you have any questions please let us know.

Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in our lower environment before you run in production.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • How do Zoom Application Testing | Working or Not
  • Powershell script to test website status up or down on a local or remote computers
  • Solved: Server execution failed windows 10 Server 2016 and 2019
  • How to Fix windows 10 version 1903 error 0xc1900223
  • Free Music Making Software List One Can Try Out
  • About Us
  • CONTACT US
  • Disclaimer
  • Privacy Policy

Copyright © 2023 techdiip.com