-
-
Save KelvinTegelaar/5ba86c5d0c4b66582f5ed77ea5f77287 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function write-DRMMDiag ($messages) { | |
write-host '<-Start Diagnostic->' | |
foreach ($Message in $Messages) { $Message } | |
write-host '<-End Diagnostic->' | |
} function write-DRRMAlert ($message) { | |
write-host '<-Start Result->' | |
write-host "Alert=$message" | |
write-host '<-End Result->' | |
} | |
$version = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").CurrentVersion | |
if ($Version -lt "6.3") { | |
write-DRRMAlert "Unsupported OS. Only Server 2012R2 and up are supported." | |
exit 1 | |
} | |
$Date = (get-date).AddHours(-48) | |
$SessionsList = & "C:\Program Files\Backup Manager\clienttool.exe" -machine-readable control.session.list -delimiter "," | convertfrom-csv -Delimiter "," | where-object { $_.state -ne "Completed" -and [datetime]$_.start -gt $Date } | |
$FailedBackups = foreach ($session in $SessionsList) { | |
if ($Session.state -eq 'InProcess' -and $session.START -lt (get-date).AddHours(-23)) { "Backup has been running for over 23 hours. Backup Started at $($session.START)" } | |
if ($Session.state -eq 'CompletedwithErrors') { "Backup has completed with an error. Backup Started at $($session.START)" } | |
if ($Session.state -eq 'Failed') { "Backup has failed with an error. Backup Started at $($session.START)" } | |
if ($Session.state -eq 'Skipped') { "Backup has been skipped as previous job was still running. Backup Started at $($session.START)" } | |
} | |
if ($FailedBackups) { | |
write-DRRMAlert "Failed backups found. Please check diagnostic information" | |
write-DRMMDiag ($FailedBackups, $SessionsList | Out-String) | |
exit 1 | |
} | |
else { | |
write-DRRMAlert "Healthy. No Failed backups" | |
write-DRMMDiag ($FailedBackups, $SessionsList | Out-String) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment