Skip to content

Instantly share code, notes, and snippets.

@KelvinTegelaar
Created Oct 21, 2020
Embed
What would you like to do?
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