Greetings all,
I currently have a script that returns the number of days since the last sucessful Windows backup. We found a couple of servers that don't have Windows backup configured so there is no "Microsoft-Windows-Backup" file causing the script to error out and return no numeric value to the monitoring software. I would like "$span" to hold the value of "99" if the script doesn't find the "Microsoft-Windows-Backup" file. I would also like the comment "No backup configured" in the AA.csv file. Here is the scrirpt I'm using.
$t = [DateTime]::Now.AddDays(0)
$Event = Get-WinEvent 'Microsoft-Windows-Backup' |
Where-Object{$_.ID -eq "4"} | Select-Object -First 1 ID,TimeCreated -EA STOP
$Event | export-csv C:\"program files"\"Zabbix Agent"\AA.csv -NoType
$span = (($t) - $Event.timecreated).Days
Write-Host $span
Thanks in advance