· 6 years ago · Aug 02, 2019, 09:16 PM
1
2$Body = ""
3$reports = ""
4$Report = ""
5$Table = ""
6$Body = @"
7<html>
8<body>
9 <img src="cid:att" />
10 <br /><BR>
11 Good Morning <BR><BR>
12 Veeam Backup Status for $(Get-Date). <BR><BR><BR><BR>
13
14 Thank you,<BR>
15 IT Team<BR><BR><BR>
16"@
17
18$accessKeyID = ""
19$secretAccessKey = ""
20$RegionEndpoint = "us-west-1"
21Initialize-AWSDefaults -Region $RegionEndpoint -AccessKey $accessKeyID -SecretKey $secretAccessKey
22
23$days = (Get-Date).AddDays(-30)
24$Reports = get-s3object -BucketName BUCKETNAME| Where { $_.Key -like "*veeam*" -and $_.StorageClass -eq "STANDARD" -and $_.LastModified -gt $days }
25
26$Table = "<table width=""800"">"
27foreach ($Report in $Reports) {
28 $CN = $report.key -split "/"
29 $PreviousName = $CompanyName
30 $CompanyName = $CN[0]
31 if ($PreviousName -ne $CompanyName) {
32 $Table += "<TD><h2>$CompanyName</h2></TD>`n"
33 }
34 else {
35 #write-host "Not writing dupe"
36 }
37
38 $PreviousSubSite = $SubSite
39
40 }
41 $body += "</table>`n"
42 $uri = "https://BUCKETNAME.s3-us-west-1.amazonaws.com/" + $Report.key
43 write-host $uri
44 $page = [system.Text.Encoding]::Unicode.GetString((Invoke-WebRequest $uri).RawContentStream.ToArray())
45 $StatusSummary = @()
46 $regex = '<tr>(.*?)<.tr>'
47 $StatusSummary = ($page | Select-String -Pattern $regex -allmatches | % { $_.Matches } | % { $_.Value })
48 $ScrubedStatus = $StatusSummary -replace '<table cellspacing="0" cellpadding="0" width="100%" border="0" style="border-collapse: collapse;">'
49 $TimeTable = @()
50 $tregex = '<td colspan="9" class="sessionDetails" style="border-style: solid; border-color:#a7a9ac; border-width: 1px 1px 0 1px;height: 35px;background-color: #f3f4f4;font-size: 16px;vertical-align: middle;padding: 5px 0 0 15px;color: #626365; font-family: Tahoma;">(.*?)<.td>'
51 $TimeTable = ($page | Select-String -Pattern $tregex -allmatches | % { $_.Matches } | % { $_.Value })
52 $ScrubbedTime = $TimeTable -replace '<table cellspacing="0" cellpadding="0" width="100%" border="0" style="border-collapse: collapse;">'
53 $ErrorSummary = @()
54 $eregex = '<span class="small_label" style="font-size: 10px;">(.*?)<.span>'
55 $ErrorSummary = ($page | Select-String -Pattern $eregex -allmatches | % { $_.Matches } | % { $_.Value })
56 $ScrubbedErrors = $ErrorSummary -replace '<table cellspacing="0" cellpadding="0" width="100%" border="0" style="border-collapse: collapse;">'
57
58 foreach ($Status in $ScrubedStatus) {
59
60 if ($Status -eq $PreviousStatus) {
61 #write-host "Not Duping Status"
62 }
63 else {
64
65 $Table += "<tr>$Status</tr>"
66 }
67 $PreviousStatus = $Status
68 foreach ($VError in $ScrubbedErrors) {
69
70 if ($VError -eq $PreviousError){
71 #write-host "Not Duping Error"
72 }
73 else {
74 $Table += "<tr>$VError</tr>"
75 }
76 $PreviousError = $VError
77 }
78 }
79
80}
81$Table += "</table>`n"
82$body += "$Table"
83$body += "</body>"
84$body += "</html>"
85
86$SMTPServer = ""
87$EmailFrom = "Do Not Reply <donotreply@123.com>"
88$EmailSubject = "Veeam Backup Status $(Get-Date)"
89$Image = "C:\utils\maintenance.jpg"
90$Message = new-object Net.Mail.MailMessage
91
92# Check your report without emailing
93$Body | Out-File "C:\utils\EmailReport.html"
94
95Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue
96$att = new-object Net.Mail.Attachment($Image)
97$att.ContentId = "att"
98$smtpPort = "587"
99$smtp = new-object Net.Mail.SmtpClient($smtpServer, $smtpPort)
100$Message.From = $EmailFrom
101$Message.To.Add("test <Test@123.com>")
102$Message.Subject = $EmailSubject
103$Message.Body = $body
104$Message.IsBodyHTML = $true
105$Message.Attachments.Add($att)
106
107$smtp.Send($Message)
108$att.Dispose()