Advertisement
Guest User

$FokPowerShell

a guest
Mar 6th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $URLListFile = "C:\Automation\URLList.txt"  
  2. $URLList = Get-Content $URLListFile -ErrorAction SilentlyContinue
  3.   $Result = @()
  4.  
  5.  
  6.   Foreach($Uri in $URLList) {
  7.   $time = try{
  8.   $request = $null
  9.  
  10.   $result1 = Measure-Command { $request = Invoke-WebRequest -Uri $uri }
  11.   $result1.TotalMilliSeconds
  12.   }  
  13.   catch
  14.   {
  15.  
  16.    $request = $_.Exception.Response
  17.    $time = -1
  18.   }  
  19.   $result += [PSCustomObject] @{
  20.   Time = Get-Date;
  21.   Uri = $uri;
  22.   StatusCode = [int] $request.StatusCode;
  23.   StatusDescription = $request.StatusDescription;
  24.   ResponseLength = $request.RawContentLength;
  25.   TimeTaken =  $time;  
  26.   }
  27.  
  28. }
  29.  
  30. if($result -ne $null)
  31. {
  32.     $Outputreport = "<HTML><TITLE>Website Report Status</TITLE><BODY background-color:peachpuff><font color =""#99000"" face=""Microsoft Tai le""><H2> Website Report Status </H2></font><Table border=1 cellpadding=0 cellspacing=0><TR bgcolor=gray align=center><TD><B>URL</B></TD><TD><B> Code </B></TD><TD><B> Status </B></TD><TD><B> Duration </B></TD><TD><B> MS (Ping) </B></TD</TR>"
  33.     Foreach($Entry in $Result)
  34.     {
  35.         if($Entry.StatusCode -ne "200")
  36.         {
  37.            $Outputreport += "<TR bgcolor=red>"
  38.         }
  39.         else
  40.         {
  41.             $Outputreport += "<TR>"
  42.         }
  43.         $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>"
  44.     }
  45.     $Outputreport += "</Table></BODY></HTML>"
  46. }
  47.  
  48. $Outputreport | out-file C:\Automation\URLReport.htm
  49. Invoke-Item C:\Automation\URLReport.htm  
  50.  
  51. <#
  52. $EmailFrom = "mis.solutions.testing@gmail.com"
  53. $EmailTo = "mdebeer@mis-solutions.com"
  54. $EmailSubject = "AFCOG Intranet Report"
  55. $emailbody = " body message "
  56. $SMTPServer = "smtp.gmail.com"
  57. $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
  58. $SMTPClient.EnableSsl = $true
  59. $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("mis.solutions.testing@gmail.com", "MIS-TESTING01");
  60. $EmailAttachment = "C:\Automation\URLReport.htm"
  61. $SMTPClient.Send($EmailFrom, $EmailTo, $EmailAttachment, $EmailSubject, $emailbody)
  62. #>
  63.  
  64.  
  65. $Date = get-date
  66.  
  67. $From = "mis.solutions.testing@gmail.com"
  68. $To = "mdebeer@mis-solutions.com"
  69. $Subject = "AFCOG Intranet Report - $Date"
  70. $Body = "See attached page for confirmation."
  71. $FileAttach = "C:\Automation\URLReport.htm"
  72. $SMTPServer = "smtp.gmail.com"
  73.  
  74. $Attachment = new-object Net.Mail.Attachment($FileAttach)
  75. $SMTP = new-object Net.Mail.SmtpClient($SMTPServer)
  76. $MSG = new-object Net.Mail.MailMessage($From, $To, $Subject, $Body)
  77. $MSG.attachments.add($Attachment)
  78. $SMTP.send($msg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement