Acronis Backup Job Health Monitoring Script

I made slight modifications to the Acronis Backup Job Health Monitoring that Syncro released. The dropdown variable is the same and still needed.

-Added Exit 1 to indicate failures.
-Added Else statement to log that the backups are healthy rather than it being blank.
-Changed backup categories so I could apply different ARs with different subjects. May be a better way to do it, feel free to change them all back to just ‘backup’

Import-Module $env:SyncroModule

try
{
    $Activities = & "C:\Program Files\BackupClient\CommandLineTool\acrocmd.exe" list activities --output raw  | ConvertFrom-Csv -Delimiter "`t" -Header 'Name', 'Machine', 'State', 'Progress', 'Start', 'Elapsed', 'estimated', 'GUID', 'Resource','Result' | Where-Object { $_.Name -NE "The operation completed successfully." }
}
catch
{
    Rmm-Alert -Category 'Backup1' -Body "Error, could not retrieve backup jobs and tasks."
    Write-Host "-Error, could not retrieve backup jobs and tasks."
    Exit 1
}

$template = 'dd.MM.yyyy HH:mm:ss'
$TasksExecutedInLastWeek = $Activities | Where-Object { [DateTime]::ParseExact($_.'start', $template, $null) -gt (Get-Date).adddays(-$MaxDaysWithoutSuccessfulBackup) }
$TasksExecutedInLastDay = $Activities | Where-Object { [DateTime]::ParseExact($_.'start', $template, $null) -gt (Get-Date).adddays('-1') }

if (!$TasksExecutedInLastWeek)
{
    Rmm-Alert -Category 'Backup2' -Body "This device has not had any backup job for $MaxDaysWithoutSuccessfulBackup days."
    Write-Host "-This device has not had any backup job for $MaxDaysWithoutSuccessfulBackup days."
    Exit 1
}

foreach ($Task in $TasksExecutedInLastWeek)
{
    if ($Task.state -eq "running" -and [datetime]$task.elapsed -gt [datetime]"23:59:00")
    {
        Rmm-Alert -Category 'Backup3' -Body "This device has been running a backup for over 24 hours."
        Write-Host "This device has been running a backup for over 24 hours."
        Exit 1
    }
}

$FailedJobs = $TasksExecutedInLastDay | Where-Object -Property 'Result' -ne 'succeeded'

if($FailedJobs.length -ge 1)
{
    Rmm-Alert -Category 'Backup4' -Body "A failed backup has been detected."
    Write-Host "A failed backup has been detected."
    Exit 1
}
else {
    Write-Host "Backups are current and healthy"
}