PowerShell script exchange
Post Reply
arun.kr
Service Provider
Posts: 25
Liked: never
Joined: Aug 16, 2014 1:13 am
Full Name: Arun Kumar
Contact:

Count number of Restore points for each VM in a backup job

Post by arun.kr »

Hello Everyone,

My object to prepare a report that will look like this
JobName VMName JobType LastBackupResult LastBackupDate NumberOfRestorePOints

I started with below code

Code: Select all

$vms = (get-vbrbackup -name aecl*).GetObjects() | select name
foreach($Vm in $vms){
$RP = Get-VBRRestorePoint -Name $vm.Name
$RPCount = $RP | Measure-Object
new-object PSObject -property @{
 "name" = $RP.name | select -First 1 | sort name
 "Restore Point" =  $RPCount.Count
} 
}
and it worked like charm. Then I added few more lines to fetch more details for my report

Code: Select all

$details = @()
$jobname = @("JobA", "JobB", "JobC", "JObD")
$jobs = Get-VBRJob -Name $jobname 
foreach ($job in $jobs){
$vms = Get-VBRJobObject -Job $job
    foreach($Vm in $vms){
    $RP = Get-VBRRestorePoint -Name $vm.Name
    $RPCount = $RP | Measure-Object

    $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 "serverName" -Value $RP.vmname | select -First 1 
    $columns | Add-Member -MemberType NoteProperty -Name "Count" -Value $RP.count

    $details += $columns
    }
}
Disconnect-VBRServer
$details | Export-Csv c:\temp\report.csv
Everything is OK except I am not getting VM name in the report. This is how output looks like

Job Name Job Type Last Backup Result server Name Count
JObA Backup Warning System.Object[] 90

One ore thing I would like to add here once script execution finished, I ran only $RP.vmname | select -First 1 and it is showing the VM name.
Not sure what is wrong with the code. We are using VBR V10.

Thanks in advance!
chris.arceneaux
VeeaMVP
Posts: 695
Liked: 374 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: Count number of Restore points for each VM in a backup job

Post by chris.arceneaux »

Hi Arun,

Please see below for working code. The main difference is the method you were using to capture VM names. Get-VBRJobObject returns the objects included/excluded as you'd see things when editing a job within the console and this isn't always a VM. To find which VMs were backed up in a job, we look to the backups for that information.

Code: Select all

$details = @()
$jobname = @("veeam", "vmware")
$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 "serverName" -Value $vm.name 
        $columns | Add-Member -MemberType NoteProperty -Name "Count" -Value $rp.count

        $details += $columns
    }
}
Disconnect-VBRServer
$details | Export-Csv c:\temp\report.csv
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests