PowerShell script exchange
Post Reply
kenshoohustle
Novice
Posts: 6
Liked: never
Joined: Nov 11, 2022 4:48 pm
Full Name: Kent Martin
Contact:

Veeam Restore Points Notification

Post by kenshoohustle »

Hi Everyone,

I am creating a report on counting the restore points per backup job.
However, upon using this script, the result is different from what I want.

The result of the output looks like this:
Job Name Job Type Last Backup Result Server Name Count
Server_D EpAgentBackup Success 0
Server_VM Backup Success Server 25

All of the restore points of "Server" is being counted for the jobname Server_VM.
It should be:
Server_D count = 18
Server_VM count = 7

The backup is File level and VM level, hence the "Server_D" - from D: drive and "Server_VM" for the VM itself.
It there a way to count for different job name and not for the vm name?

Code: Select all

$details = @()
$jobname = @("Server_D", "Server_VM")
$jobs = Get-VBRJob -Name $jobname
$backups = Get-VBRBackup
$rps = Get-VBRRestorePoint
foreach ($job in $jobs) {
    $backup = $backups | Where-Object {$_.JobId -eq $job.id}
    $vms = $backup.GetObjectOibsAll()
    foreach ($vm in $vms) {
        $rp = $rps | Where-Object {$_.vmname -eq $vm.Name}

        $columns = New-Object psobject
        $columns | Add-Member -MemberType NoteProperty -Name "Job Name" -Value $job.Name
        $columns | Add-Member -MemberType NoteProperty -Name "Job Type" -Value $job.JobType
        $columns | Add-Member -MemberType NoteProperty -Name "Last Backup Result" -Value $job.GetLastResult()
        $columns | Add-Member -MemberType NoteProperty -Name "Server Name" -Value $vm.name 
        $columns | Add-Member -MemberType NoteProperty -Name "Count" -Value $rp.count

        $details += $columns
    }
}
Disconnect-VBRServer
$details | Export-Csv c:\temp\report.csv
The script I used is from chris.arceneaux:
powershell-f26/count-number-of-restore- ... 67754.html

Thanks in advance.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Veeam Restore Points Notification

Post by oleg.feoktistov » 1 person likes this post

Hi Kent,

I couldn't reproduce your issue in my lab, but in my case Count is always zeroed.
Try using GetObjects() method on $backup instead:

Code: Select all

$vms = $backup.GetObjects()
Also, match restore points by object id explicitly rather than by vm name:

Code: Select all

$rp = $rps | Where-Object {$_.ObjectId -eq $vm.Id}

Best regards,
Oleg
kenshoohustle
Novice
Posts: 6
Liked: never
Joined: Nov 11, 2022 4:48 pm
Full Name: Kent Martin
Contact:

Re: Veeam Restore Points Notification

Post by kenshoohustle »

Hi Oleg,

That worked for me for the Server_VM showing count with 7 restore points. However, it didn't get the Server_D counts, but I think I can figure it out now.
Will post an update after I solved this.

Thank you very much.

Best regards,
Kent
kenshoohustle
Novice
Posts: 6
Liked: never
Joined: Nov 11, 2022 4:48 pm
Full Name: Kent Martin
Contact:

Re: Veeam Restore Points Notification

Post by kenshoohustle »

Still stuck on this.

I think using the "GetObjects()" won't include the backup jobs that are volume/folder level.
Only the backup jobs for VMs.

I'm thinking of just subtracting the result of the 1st script to the new script to get the desired result for Server_D jobs cause I always get count 0.
Or is there another way?

Apologies as I am still new on scripting.

Thank you.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Veeam Restore Points Notification

Post by oleg.feoktistov » 1 person likes this post

Hi Kent,

I think I might know where the issue is. Try adding this validation flow right before foreach ($vm in $vms) statement:

Code: Select all

    $child = $backup.FindChildBackups()
    if ($child) {
    $vms = $child.GetObjects()
    }
    else {
     $vms = $backup.GetObjects()
    }
Best regards,
Oleg
kenshoohustle
Novice
Posts: 6
Liked: never
Joined: Nov 11, 2022 4:48 pm
Full Name: Kent Martin
Contact:

Re: Veeam Restore Points Notification

Post by kenshoohustle »

Hi Oleg,

It works like a charm. Thank you very much.
I will now just figure out how to improve the script to our needed report.

Again, thank you for the wisdom.

Best regards,
Kent
Post Reply

Who is online

Users browsing this forum: aruns and 13 guests