PowerShell script exchange
Post Reply
metermac
Lurker
Posts: 1
Liked: never
Joined: Jun 15, 2022 9:51 pm
Full Name: James
Contact:

No VBRJobObjects from Imported Backup Job

Post by metermac »

I can successfully import a backup job from a repository, but when I attempt to retrieve the VMs using Get-VBRJob & Get-VBRJobObject, the result set is null.

Code: Select all

Import-VBRBackup -FileName $JobFileName -Repository $ImportRepository
$BackupJobs = Get-VBRBackup
foreach ($JobName in $BackupJobs) {
    #Get list of VMs for backup jobs
    $objects = Get-VBRJob -Name $JobName.Name | Get-VBRJobObject
    foreach ($obj in $objects) {
        Write-Output $obj.Name
    }
}
That prints out the name for VMs (objects) of all backup jobs that aren't imported, but nothing is printed out for my imported backup job.

Changing

Code: Select all

$objects = Get-VBRJob -Name $JobName.Name | Get-VBRJobObject
to

Code: Select all

$objects = $JobName.GetObjects()
Results in the names of VMs for all backup jobs (imported or not) printed out.

Any idea why?
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: No VBRJobObjects from Imported Backup Job

Post by oleg.feoktistov »

Hi James,

On backup import we add information about the backup, but the corresponding job is not being imported along the way.
You can visualize what I mean by looking at JobId property of an imported backup:

Code: Select all

PS C:\Windows\system32> $backup = Get-VBRBackup -Name 'Backup to SOBR Cloud'
$backup | select Name, JobId, JobName

Name                 JobId                                JobName             
----                 -----                                -------             
Backup to SOBR Cloud 00000000-0000-0000-0000-000000000000 Backup to SOBR Cloud
As you can see, JobId is zeroed because the associated job is not registered in a new VBR.

So, in your first approach there is just nothing to return starting with Get-VBRJob cmdlet.
In your second approach you invoke GetObjects() on a backup instance. We have information about the imported backups, so we can find the objects this backup includes.

P.S. For your variables I would advise using names relevant to the object types and cmdlets you are dealing with to avoid confusion:
$backups for Get-VBRBackup, $backupJobs for Get-VBRJob etc. I think, using $BackupJobs for Get-VBRBackup and $JobName for a single backup instance tempts you to refer to jobs, not backups. Especially, when a script is huge and you can't always keep track of all the entities.


Thanks,
Oleg
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests