In our previous post we already discussed about “How to check response code from a website using PowerShell“ by using single URL in example. Here let we discuss how to read the list of URLs from the text file and validate the list of URL . Finally script will generate the Excel file with the output result.
$URLListFile = "D:\PowerShell\URLList.txt"
#Reading the list of URLs from the URLList.txt file
$URLList = Get-Content $URLListFile -ErrorAction SilentlyContinue
#Declaring Array
$Result = @()
$FormatGenerater = "<HTML><BODY background-color:grey><font color =""black""><H2> snfcms cert </H2>
</font><Table border=1 cellpadding=0 cellspacing=0><TR bgcolor=gray align=center><TD><B>URL</B>
</TD><TD><B>StatusCode</B></TD></TR>"
Foreach($URL in $URLList)
{
$time = try{
$request = $null
#Measure-Command : Measures the time it takes to run script blocks and cmdlets.
$response = Measure-Command { $request = Invoke-WebRequest -Uri $URL }
$response.TotalMilliseconds
}
catch
{
$request = $_.Exception.Response
$time = -1
}
$result += [PSCustomObject] @{
Time = Get-Date;
Uri = $URL;
StatusCode = [int] $request.StatusCode;
}
}
if($result -ne $null)
{
Foreach($Entry in $Result)
{
if($Entry.StatusCode -ne "200")
{
$FormatGenerater += "<TR bgcolor=grey>"
}
else
{
$FormatGenerater += "<TR bgcolor=lightgreen>"
}
$FormatGenerater += "<TD>$($Entry.uri)</TD><TD align=center>$($Entry.StatusCode)</TD></TR>"
}
$FormatGenerater += "</Table></BODY></HTML>"
}
$FormatGenerater | out-file D:\PowerShell\SiteValidation_Results.xlsOUTPUT Excel File:
What do you think?
I hope you have idea of how to check the Website Availability Monitoring with Excel Report as output. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.

That’s pretty useful, thanks
Thanks :)
every time my status code is o, tried google and other sites
How do I get the report in mail once my website is down
how do i use this script with a security log on pop out dialog
How to perform the same operation when url are in excel and need user name password to navigate to the inner page