<# .SYNOPSIS This script is meant to report on the truncation backups of an Exchange environment with AppAssure .DESCRIPTION Checks the last truncated backup and alerts if it is over 2 days ago. .EXAMPLE .\Check-Truncation.ps1 Does a basic script run through .NOTES Written By: Paul DiMarino .CHANGE LOG v1.00 - 2016/07/06 - First version started #> #............................................ #Loads AppAssure Shell #............................................ Import-Module AppAssurePowerShellModule #............................................ # Mail Server Variables #............................................ $server = "{your smtp relay" $sender = "Your Sending Address <{address@domain.com}>" $recipient = "{address@domain.com}" $alertmessagebody = $null $alertmessagesubject = $null #............................................ # Script Variables #............................................ $compareDate = (Get-Date).AddDays(-2) $GlobalFailure = $null $ReportDate = Get-Date -Format F $AppAssureServer = $env:computername #............................................ # Script Begins Processing Protected Servers #............................................ Write-Host "--------------- Retrieving Protected Servers ---------------`n" -ForegroundColor Cyan $servers = (get-protectedservers).displayname Write-Host "$($servers.count) Protected Servers found in this AppAssure instance...`n" -ForegroundColor Green # Sets Email and File Information $BackupIntro = "

AppAssure Protected Exchange Servers Component Alert Summary:

" $BackupReport = @() ForEach ($server in $servers) { Write-Host "`n--------------- Processing Backup State of $($server) ---------------" -ForegroundColor Cyan $LastGood = (Get-Completedjobs -ProtectedServer $server | where {($_.Summary -like "*with log truncation*" -AND $_.Status -eq "Succeeded")} | select-object EndTime | sort-object EndTime -Descending | select-object -First 1).EndTime $Alert = Get-Completedjobs -ProtectedServer $server | where {($_.Summary -like "*with log truncation*" -AND $_.Status -eq "Succeeded")} | Where-Object {$_.EndTime -ge $compareDate} If (!($Alert)) { $BackupStatus = "FAIL" If ($GlobalFailure) { $GlobalFailure += ", "+$server } Else { $GlobalFailure = $server } } Else { $BackupStatus = "PASS" } $BackupReportObj = New-Object PSObject $BackupReportObj | Add-Member NoteProperty -Name "Server" -Value $server $BackupReportObj | Add-Member NoteProperty -Name "Backup Status" -Value $BackupStatus $BackupReportObj | Add-Member NoteProperty -Name "Last Truncation" -Value $LastGood $BackupReport += $BackupReportObj ####Begin Backup Report Table HTML### $BackupReportHTML = $null #Begin Table Header $htmltableheader = "

" $BackupReportHTML += $htmltableheader #End Table Header #Begin Table Rows ForEach ($row in $BackupReport) { $htmltablerow = "" $htmltablerow = $htmltablerow + "" #Fail if status is FAIL switch ($($row."Backup Status")) { "PASS" { $htmltablerow = $htmltablerow + "" } default { $htmltablerow = $htmltablerow + "" } } $htmltablerow = $htmltablerow + "" $htmltablerow = $htmltablerow + "" $BackupReportHTML += $htmltablerow } $BackupReportHTML += "
Server Backup Status Last Truncation
$($row."Server")$($row."Backup Status")$($row."Backup Status")$($row."Last Truncation")

" } #............................................ # Output report to the console #............................................ Write-Host "`n ---- Protected Server Backup Report ---- " $BackupReport | ft #............................................ # Output the report to HTML #............................................ $AppAssureReportHTML = $BackupIntro + $BackupReportHTML $AlertMessageBody += $AppAssureReportHTML $htmlhead="

AppAssure Protected Exchange Server Report

AppAssure Backup State as of $reportdate

" $htmltail = "" $htmlreport = $htmlhead + $alertmessagebody + $htmltail If ($GlobalFailure) { $alertmessagesubject = $AppAssureServer+" - Truncation Failure Alert for "+$GlobalFailure } Else { $alertmessagesubject = $AppAssureServer+" - Backup Report - All Pass" } Send-MailMessage -To $recipient -Subject $alertmessagesubject -SmtpServer $server -From $sender -Body $htmlreport -BodyAsHtml -Encoding ([System.Text.Encoding]::UTF8)