Code: Select all
# CheckVeeamJob: check when Veeam job last ran.
Function CheckVeeamJob($Id, $Name) {
Write-Host "Checking Veeam $Name job"
$Job = Get-VBRComputerBackupJob -Id $Id -EA Silent
If (!$Job) {WriteFault "Can't find Veeam backup job for $Name"; Return}
$Sessions = Get-VBRComputerBackupJobSession -Name $Job.Name | ? Result -eq "Success" | Sort CreationTime -Descending
If (!$Sessions) {WriteFault "Can't find any success jobs for $Name"; Exit}
$LastSession = $Sessions[0]
$Elapsed = New-TimeSpan $LastSession.CreationTime (Get-Date)
If ($Elapsed.TotalHours -gt 25) {WriteFault ("$Name backup job not run successfully for over 24 hours. Last run {0:N} hours ago" -f $Elapsed.TotalHours)}
}