Website Availability Monitoring / URL Monitoring

Powershell script for website availability monitoring/URL Monitoring. This Script will take the list of URLs from a text tile( in this case from D:\URLList.txt)as input, and results output with URL, StatusCode, Description, Response Length and time taken fields in a HTML Report.

– This Script will take the list of URLs from a text tile( in this case from D:\URLList.txt), and results output with URL, StatusCode, Description. Response Length and the time taken fields in a HTML format report ( C:\Scripts\Test.htm)

– Powershell 3 required

– You can run this script in a schedule task to run at regular intervals for continuous monitoring

I hope it will be useful.



## The URI list to test
$URLListFile = “D:\URLList.txt”
$URLList = Get-Content $URLListFile -ErrorAction SilentlyContinue
$Result = @()

Foreach($Uri in $URLList) {
$time = try{
$request = $null
## Request the URI, and measure how long the response took.
$result1 = Measure-Command { $request = Invoke-WebRequest -Uri $uri }
<# If the request generated an exception (i.e.: 500 server
error or 404 not found), we can pull the status code from the
Exception.Response property #>
$request = $_.Exception.Response
$time = -1
$result += [PSCustomObject] @{
Time = Get-Date;
Uri = $uri;
StatusCode = [int] $request.StatusCode;
StatusDescription = $request.StatusDescription;
ResponseLength = $request.RawContentLength;
TimeTaken = $time;

#Prepare email body in HTML format
if($result -ne $null)
$Outputreport = “<HTML><TITLE>Website Availability Report</TITLE><BODY background-color:peachpuff><font color =””#99000″” face=””Microsoft Tai le””><H2> Website Availability Report </H2></font><Table border=1 cellpadding=0 cellspacing=0><TR bgcolor=gray align=center><TD><B>URL</B></TD><TD><B>StatusCode</B></TD><TD><B>StatusDescription</B></TD><TD><B>ResponseLength</B></TD><TD><B>TimeTaken</B></TD</TR>”
Foreach($Entry in $Result)
if($Entry.StatusCode -ne “200”)
$Outputreport += “<TR bgcolor=red>”
$Outputreport += “<TR>”
$Outputreport += “<TD>$($Entry.uri)</TD><TD align=center>$($Entry.StatusCode)</TD><TD align=center>$($Entry.StatusDescription)</TD><TD align=center>$($Entry.ResponseLength)</TD><TD align=center>$($Entry.timetaken)</TD></TR>”
$Outputreport += “</Table></BODY></HTML>”

$Outputreport | out-file C:\Scripts\Test.htm
Invoke-Expression C:\Scripts\Test.htm


Be the first to comment

Leave a Reply

Your email address will not be published.