I was wondering if there is a way to use PowerShell to determine if a machine in a protection group has not backed up in the last 30 days. Obviously in Inventory there are protection groups that have machines in them and a status of “Last Agent Backup”. Is it possible to generate a report that displays that information?
Basically I would like to put the script into task scheduler and have it run the 2nd and the 24th of every month.
Any advice?
# Load Veeam PowerShell Module
Import-Module Veeam.Backup.PowerShell
# Define protection group names
$protectionGroupNames = @("Example Protection Group", "Example Protection Group 2")
# Get the current date and time window
$timeWindow = (Get-Date).AddDays(-30)
# Initialize array to store report data
$reportData = @()
foreach ($groupName in $protectionGroupNames) {
# Get the protection group
$protectionGroup = Get-VBRProtectionGroup -Name $groupName
# Get details of the machines in the protection group
$machines = Get-VBRDiscoveredComputer -ProtectionGroup $protectionGroup
foreach ($machine in $machines) {
# Get the last backup session for the machine
$lastSession = Get-VBRBackupSession | Where-Object { $_.Name -like "*$($machine.Name)*" } | Sort-Object EndTime -Descending | Select-Object -First 1
# Add to report
$reportData += [PSCustomObject]@{
ProtectionGroup = $groupName
MachineName = $machine.Name
LastBackup = $lastSession.EndTime
Status = $lastSession.State
}
}
}
# Export report to CSV
$reportPath = "C:\Reports\PhysicalInfrastructureBackupReport_$(Get-Date -Format 'yyyyMMdd_HHmmss').csv"
$reportData | Export-Csv -Path $reportPath -NoTypeInformation