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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
$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.xls |
OUTPUT 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.
How to perform the same operation when url are in excel and need user name password to navigate to the inner page
how do i use this script with a security log on pop out dialog
How do I get the report in mail once my website is down
every time my status code is o, tried google and other sites
Thanks :)
That’s pretty useful, thanks