We get alerts from time to time that SharePoint and Skype Websites might not be loading correctly or not at all. The following is a script that will generate a report, with time and date, showing the availability of the websites in question and the time it takes to load them.
First off, you want to create a text file called URLList.txt that will have the list of websites you want to check. I save the file in the C:\PowerShell directory but you can change the path to where you need it. If this happens often, having this list prepared will help you evaluate the environment quickly and allow you to troubleshoot if necessary efficiently.
Here is the script:
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | ##WebsiteChecker.ps1 built by Lance Lingerfelt - LDLNET LLC - Life In Action! E-Mail: lance.lingerfelt@ldlnet.net - Learn, Do, Live! ## Provide the path to the URL list to test $URLListFile = "c:\PowerShell\URLList.txt" $URLList = Get-Content $URLListFile -ErrorAction SilentlyContinue $Result = @() $booltime = 0 ##Begin the function cmdlet and define the variables Foreach ($Uri in $URLList) { $time = try{ $request = $null ## Request the URL, and measure how long the response took. $result1 = Measure-Command { $request = Invoke-WebRequest -Uri $uri -UseDefaultCredentials } $result1.Totalseconds $ResultsTime = $result1.TotalSeconds if($ResultsTime -gt 0) { write-host $uri, $ResultsTime $booltime++ write-host $booltime } } catch { ## 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 the output report body in HTML format if($booltime -gt 0 ) { if($result -ne $null) { $Outputreport = "<HTML><TITLE>Website Availability Report</TITLE><BODY background-color:peachpuff><font color =""#99000"" face=""Microsoft Table""><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>" } else { $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>" } $Filename = "C:\PowerShell\URLCheck-" + [DateTime]::Now.ToString("yyyyMMdd-HHmmss") + ".htm" $Outputreport | out-file $Filename ## Open the file for viewing Invoke-Item $Filename } |
Here is your output: