I have half created this, half taken parts from other scripts and the output I'm getting is far larger than I would expect?
It is outputting 1000+ results, I only have 4 Backup jobs, with 1 VM in each and 7 restore points, so the max result I would expect would be 28?
I suspect I have looped in the wrong place, but I couldn't work it out. Any ideas?
Code: Select all
Add-PSSnapin VeeamPSSnapin
$backups = get-vbrbackup | ? { $_.JobType -match "^(Endpoint)?Backup$" }
$jobs = Get-VBRJob
$table = @()
foreach ($backup in $backups) {
$objects = $backup.GetObjectOibsAll()
$storages = $backup.GetAllStorages()
foreach ($object in $objects) {
foreach ($storage in $storages) {
If ($backup.info.jobtargethostid -match $storage.info.HostID) {
$storagePath = $storage.filepath
$StorageBackupSize = $storage.Stats.BackupSize
}
else {
$storagePath = $null
$StorageBackupSize = $null
}
foreach ($job in $jobs) {
If ($backup.info.jobtargethostid -match $job.info.targethostid) {
$NextRun = $job | Get-VBRJobScheduleOptions | Select -ExpandProperty nextrun
}
$table += New-Object -TypeName psobject -Property @{
BackupName=$backup.Name;
ObjectName=$object.Name;
ObjectCount=$object.CountOfValidOibs;
ObjectCreationTime=$object.CreationTime
NextRun=$nextrun
StoragePath=$storagePath
StorageBackupSize=[math]::round($StorageBackupSize /1Gb, 3)
}
}
}
}
}
$table | Sort-Object -Property "BackupName" |
select @{n='Job Name';e={$_.BackupName}},
@{n='Backup Name';e={$_.ObjectName}},
@{n='Restore Points';e={$_.ObjectCount}},
@{n='Last Backup Time';e={$_.ObjectCreationTime}},
@{n='Next Run';e={$_.NextRun}},
@{n='Storage Path';e={$_.StoragePath}},
@{n='Storage Backup Size (GB)';e={$_.StorageBackupSize}} | fl