Quantcast
Channel: for each parallel
Viewing all articles
Browse latest Browse all 9

for each parallel

$
0
0

hi all

i fail to understand what mistake i have committed on the script .

i get only one result on the output even when i have multiple urls on the input file

please advise

Workflow check_site {
  $URLListFile = "C:\Users\Documents\URLList.txt" 
  $URLList = Get-Content $URLListFile -ErrorAction SilentlyContinue
  foreach -parallel -throttlelimit 100 ($Uri in $URLList) {

  inlinescript {
  $time = try{
  $Result = @()
  $request = $null
# write-host "Checking Response from " $Uri -ForegroundColor Cyan
   ## Request the URI, and measure how long the response took.
  $result1 = Measure-Command { $request = Invoke-WebRequest -Uri $using:uri -UseDefaultCredential}
  $using:result1.TotalMilliseconds

#Write-Host "Connected" -ForegroundColor green
  } 
  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

  #Write-Host "Sorry the site cannot be contacted " "Error code:" ([int] $request.StatusCode) "Description :" $request.StatusDescription -ForegroundColor red


   
  }  
  $result += [PSCustomObject] @{
  Time = Get-Date;
  Uri = $Using:uri;
  StatusCode = [int] $using:request.StatusCode;
  StatusDescription = $using:request.StatusDescription;
  ResponseLength = $using:request.RawContentLength;
  TimeTaken =  $Using:time; 
  }


    #Prepare email body in HTML format
if($Using: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 $Using: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:\Single.htm' -Force

}
}

}
check_site


Viewing all articles
Browse latest Browse all 9

Latest Images

Trending Articles



Latest Images