Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $URLListFile = "C:\Automation\URLList.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 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>"
- 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:\Automation\URLReport.htm
- Invoke-Item C:\Automation\URLReport.htm
- <#
- $EmailFrom = "mis.solutions.testing@gmail.com"
- $EmailTo = "mdebeer@mis-solutions.com"
- $EmailSubject = "AFCOG Intranet Report"
- $emailbody = " body message "
- $SMTPServer = "smtp.gmail.com"
- $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
- $SMTPClient.EnableSsl = $true
- $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("mis.solutions.testing@gmail.com", "MIS-TESTING01");
- $EmailAttachment = "C:\Automation\URLReport.htm"
- $SMTPClient.Send($EmailFrom, $EmailTo, $EmailAttachment, $EmailSubject, $emailbody)
- #>
- $Date = get-date
- $From = "mis.solutions.testing@gmail.com"
- $To = "mdebeer@mis-solutions.com"
- $Subject = "AFCOG Intranet Report - $Date"
- $Body = "See attached page for confirmation."
- $FileAttach = "C:\Automation\URLReport.htm"
- $SMTPServer = "smtp.gmail.com"
- $Attachment = new-object Net.Mail.Attachment($FileAttach)
- $SMTP = new-object Net.Mail.SmtpClient($SMTPServer)
- $MSG = new-object Net.Mail.MailMessage($From, $To, $Subject, $Body)
- $MSG.attachments.add($Attachment)
- $SMTP.send($msg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement