Monitors a website availability, integrity and response times by looking for a specific string on a page

	Monitor-Website.ps1 - Monitors a website availability by looking for a specific string on a page
	Monitor-Website - Website availability, integrity and response times monitoring
	The URL of the page to monitor.
	Mandatory parameter.
	The string to look for on the page
	Default is null. If not specified, only the availability of the URL is checked.
	The sleep interval between each check
	Default is 5 seconds.
	Switches the 'ErrorActionPreference' between "Continue" and "SilentlyContinue"
	Default is "no".
	File Name	: Monitor-Website.ps1 
	Author		: Fabrice ZERROUKI -
	PS D:\> .\Monitor-Website.ps1 -URL -String windows -Interval 10
	Check for "*windows*" on the page every 10 seconds
	PS D:\> .\Monitor-Website.ps1 -URL
	Check availability every 5 seconds (default value)
	no string looking for, only website availability (default value)
    [Parameter(Mandatory=$true, HelpMessage="You must provide an URL to test. (")]
    [ValidatePattern("(http(s)?://)?([\w-]+\.)+[\w-]+(/[\w- ;,./?%&=]*)?")]
    [ValidateSet( "yes", "no")]

if ($ShowErrors -eq "yes") {
} else {
$webClient=New-Object System.Net.WebClient
# Uncomment the next 2 lines if you have to use the IE configured proxy
$webClient.Headers.Add("user-agent", "PowerShell Script")

if (($URL -like "http://*") -or ($URL -like "https://*")) {
else {
$URLToCheck="http://" + $URL
$StringToCheck="*" + "$String" + "*"

Write-Host "$URLToCheck" -ForegroundColor DarkGreen;
Write-Host "$StringToCheck" -ForegroundColor DarkGreen;

Write-Host ""
while (1 -eq 1) {
   $result=($endTime - $startTime).TotalSeconds

   if (($output -like "$StringToCheck") -and ($output))
	$check="Success`t`t" + $startTime.DateTime + "`t`t" + ($endTime - $startTime).TotalSeconds + " seconds"
	Write-Host "$check"
	$check="Fail`t`t" + $startTime.DateTime + "`t`t" + ($endTime - $startTime).TotalSeconds + " seconds"
	Write-Host "$check"
	Write-Host "String `"$StringToCheck`" not found at $URLToCheck" -ForegroundColor DarkYellow;

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top