In The Beginning …

When I arrived, my first task was to find HTML logs and copy them into a spread sheet to determine the backup status. The following code is sanitised, but other than that is the original. This was where it all began;

==============================================================

Add-PSSnapin VeeamPsSnapIn
$email = “techstaff@domain.com”
$jobs = Get-VBRJob
$now = Get-Date
$date = get-date -Format ddMMHHmm
$bckuwindow = $now.AddHours(-24)
$jobs = $jobs | Sort-Object -Property Name
$report = @()
foreach ($job in $jobs){
$name = $job.Name
$latrun = $job.ScheduleOptions.LatestRunlocal
$runin = $job.IsRunning
$laststat = $job.GetLastState()
$lastres = $job.GetLastResult()
$nextrun = $job.ScheduleOptions.NextRun
$enabled = $job.IsScheduleEnabled
if($runin -eq $True){
$status = “Job Running”
}
elseif ($latrun -gt $bckuwindow){
$status = “$($lastres) on $($latrun.ToShortDateString()) at $($latrun.ToShortTimeString())”
}
elseif ($nextrun -ne “”){
$nextruntd = [datetime]$nextrun
$status = “Next Run $($nextruntd.DayOfWeek) $($nextruntd.Day) at $($nextruntd.ToShortTimeString())”
}
elseif ($enabled -eq $false){
$status = “Job Disabled”
}
elseif ($nextrun -eq “”){
$status = “Job Not Scheduled”
}
else {
$status = “Error Loading Job Details – Investigate”
}
$report += New-Object psobject -Property @{Name=$name;Status=$status}
}
$Currentcheckfile = “”Server Path”\Job_List\Job_List_Current.txt”
$checkjobname = $($jobs).name
$checkimport = Get-Content -Path $currentcheckfile
Clear-Content -Path $Currentcheckfile
Add-content -Value $checkjobname -Path $Currentcheckfile
$compare = Compare-Object -ReferenceObject (Get-content -path $Currentcheckfile) -DifferenceObject $checkimport
$comparejoblist = foreach ($comparejob in $compare){
Switch ($comparejob.sideindicator){
“<=” {
$newjoblist = @{
‘Status:’ = ‘Job Added’
‘Name:’ = $comparejob.inputobject
}
Break
}
“=>” {
$newjoblist = @{
‘Status:’ = ‘Job Removed’
‘Name:’ = $comparejob.inputobject
}
Break
}
}
New-Object -TypeName PSObject -Property $newjoblist
}
$comparehtml = $comparejoblist | ConvertTo-Html -Title “Backup Log $Date” -PreContent “<br>”
$style = “<style>BODY{font-family: Arial; font-size: 10pt;}”
$style = $style + “TABLE{border: 1px solid black; border-collapse: collapse;}”
$style = $style + “TH{border: 1px solid black; background: #dddddd; padding: 5px; }”
$style = $style + “TD{border: 1px solid black; padding: 5px; }”
$style = $style + “</style> <center>”
$finalhtml = $report | ConvertTo-Html -Title “Backup Log $Date” -Head $style -PostContent $comparehtml
$finalhtml | Out-File “”Server Path”\$date.html”
Send-MailMessage -TO $email -Subject “$env:COMPUTERNAME – Job Status Overview” -BodyAsHtml -Body “$finalhtml” -From “$env:COMPUTERNAME<$env:COMPUTERNAME@domain.com>” -SmtpServer “mail.domain.com”