Get-VeeamBackupReport.ps1
<#PSScriptInfo
.VERSION 1.1.0 .GUID a0c2c3f8-c28c-42dd-bfde-6f541057e0af .AUTHOR saw-friendship@yandex.ru .COMPANYNAME .COPYRIGHT .TAGS saw-friendship Veeam Html Report BackUpJob .LICENSEURI .PROJECTURI https://sawfriendship.wordpress.com/ .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .DESCRIPTION Veeam backup job report. You can run this script from windows task scheduler and receive html report by Email #> [CmdletBinding()] param( [switch]$AsHtml, [switch]$SendMail, [string]$MailFrom, [string]$MailTo, [string]$MailSubject = 'VeeamReport', [string]$MailServer ) if (!(Get-PSSnapin -Name VeeamPSSnapin -ErrorAction SilentlyContinue)){ if ((Get-PSSnapin -Registered -Name VeeamPSSnapin -ErrorAction SilentlyContinue)) { Add-PSSnapin VeeamPSSnapin } else { Write-Warning "VeeamPSSnapin not exist" break } } $join = ' :: ' $StatusCode = @{Failed = 0; Warning = 1; Success = 2; None = 3} $Jobs = Get-VBRJob | % { $LastBackup = try {$_.GetLastBackup()} catch {$null} $LastPointCreationTime = try {$LastBackup.LastPointCreationTime -as [DateTime]} catch {$null} $MetaUpdateTime = try {$LastBackup.MetaUpdateTime -as [DateTime]} catch {$null} $LastBackupDuration = if (($MetaUpdateTime -and $LastPointCreationTime) -and ($MetaUpdateTime -ge $LastPointCreationTime)) { ($MetaUpdateTime - $LastPointCreationTime).ToString('dd\.hh\:mm\:ss') } else { $null } $_ | Select-Object -Property @( ,@{Name = 'Name'; Expression = {$_.Name}} ,@{Name = 'LastResult'; Expression = {[String]($_.GetLastResult())}} ,@{Name = 'LastBackupStart'; Expression = {$LastPointCreationTime.ToString('yyyy-MM-dd HH:mm:ss')}} ,@{Name = 'LastBackupEnd'; Expression = {$MetaUpdateTime.ToString('yyyy-MM-dd HH:mm:ss')}} ,@{Name = 'LastBackupDuration'; Expression = {$LastBackupDuration}} ,@{Name = 'Object'; Expression = {$_.GetObjectsInJob().Location -join $join}} ) } | Sort-Object -Property @( ,@{Expression = {$StatusCode[$_.LastResult]}; Descending = $false} ,@{Expression = {$_.LastBackupStart}; Descending = $true} ) if (!$AsHtml) { $OUT = $Jobs } else { $HtmlHead = @" <style type="text/css"> table {border-collapse: collapse; width:100%;} th {border: 1px solid black; background-color:black; color:white;} td {border: 1px solid black;} </style> "@ $PreContent = @" <table bgcolor=54b948 color=fffafa><tr><td> <h1>Veeam Report</h1> <h2> Job Success: $(@($Jobs | ? {$_.LastResult -eq 'Success'}).count)<br> Job Warning: $(@($Jobs | ? {$_.LastResult -eq 'Warning'}).count)<br> Job Failed: $(@($Jobs | ? {$_.LastResult -eq 'Failed'}).count)<br> Job None: $(@($Jobs | ? {$_.LastResult -eq 'None'}).count)<br> </h2></tr></td></table><br> "@ $OUT = $Jobs | ConvertTo-Html -Head $HtmlHead -PreContent $PreContent @( ,@($join,'<br>') ,@('<td>Success</td>','<td bgcolor=54b948>Success</td>') ,@('<td>Warning</td>','<td bgcolor=ffd700>Warning</td>') ,@('<td>Failed</td>','<td bgcolor=e66761>Failed</td>') ,@('<td>None</td>','<td bgcolor=fffafa>None</td>') ) | % { $OUT = $OUT -replace @($_[0],$_[1]) } } if ($SendMail) { Send-MailMessage -Encoding utf8 -Body ($OUT | Out-String) -BodyAsHtml -To $MailTo -From $MailFrom -Subject $MailSubject -SmtpServer $MailServer } else { $OUT } |