I want to address a fix to a problem that a lot of people have been having and that I couldn't find a proper solution to here in the knowledge base. Below is a script that is working in the 17.2.30.1883 version. I did not write the whole script myself but put a couple different scripts together and tweaked it until it was working correctly. Hopefully this saves someone a headache as I worked for days without a solution. Enjoy!
param([string]$hostname = "your server name") Invoke-Command -ComputerName $hostname{ $today=(Get-Date) $dateshift=(Get-Date).AddHours(-12) $EventError=Get-WinEvent -LogName Microsoft-Windows-Backup| Where-Object {$_.TimeCreated -gt $dateshift} | Where-Object {$_.LevelDisplayName -eq "Error"} $EventWarning=Get-WinEvent -LogName Microsoft-Windows-Backup| Where-Object {$_.TimeCreated -gt $dateshift} | Where-Object {$_.LevelDisplayName -eq "Warning"} $EventOK=Get-WinEvent -LogName Microsoft-Windows-Backup| Where-Object {$_.TimeCreated -gt $dateshift} | Where-Object {$_.LevelDisplayName -eq "Information"} $backupsets=Get-WBBackupSet $lastbackup=(Get-Date)-($backupsets.BackupTime |Measure-Object -Maximum |Select-Object -ExpandProperty Maximum) $lastbkround=[math]::Floor($lastbackup.TotalHours) $x = [string] $($EventError.Count)+":OK" Write-Host $x Exit 0
You can tweak the time that it searches for an error under the $dateshift, other than that it is pretty straight forward. Let me know if you have any questions, recommendations, critiques or anything at all. Thanks.
Add comment