0

I have the following PowerShell Script, found and modified some time ago, however after checking and testing it in the past, I put this project away and wanted to check again now. However, the script should check a given website and tell how long it took to reach etc, but when I want to check with an internal website it is not working and constantly showing the cells with red color and error 200, however, external website like google or Facebook are measurable by the script. Here is the script:

$URLListFile = "C:\Users\***\Desktop\websites.txt" 
$URLList = Get-Content $URLListFile -ErrorAction SilentlyContinue

$Result = @()

  Foreach($Uri in $URLList) {
  $time = try{
  $request = $null
  $result1 = Measure-Command { $request = Invoke-WebRequest -Uri $uri }
  $result1.TotalMilliseconds
  } 
  catch
  {
   $request = $_.Exception.Response
   $time = -1
  }  
  $result += [PSCustomObject] @{
  Time = Get-Date;
  Uri = $uri;
  StatusCode = [int] $request.StatusCode;
  StatusDescription = $request.StatusDescription;
  ResponseLength = $request.RawContentLength;
  TimeTaken =  $time; 
  }

}

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>"
        }
        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>"
}

$Outputreport | out-file C:\Users\***\Desktop\Test.htm
Invoke-Expression C:\Users\***\Desktop\Test.htm  

Also attaching the picture about the result. Would you be able to help me why internal websites can not be measured, how should this script be modified so it can work? Website Availability Report

error

Hagay89700
  • 13
  • 3

1 Answers1

0

Okay, so adding this line solved my issue, as the webpage is not accepting SSL 1.0 but 1.2 only connection. [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;

Hagay89700
  • 13
  • 3