foreach 逻辑问题

Trouble with foreach logic

我正在尝试获取我所有 Veeam 备份作业中所有虚拟机的列表。这是我写的

#Add Veeam snapin
Add-PSSnapin VeeamPSSnapin

#variables
$Masterlist = @()
$jobs = Get-VBRJob

foreach($job in $jobs) {

    $backupJobObjects = Get-VBRJobObject -Job $job 

    foreach($backupJobObject in $backupJobObjects) {
        $MyObject = New-Object PSObject -Property @{ Name = $backupJobObject.Name }
    }
    $Masterlist += $MyObject
} 

$Masterlist | sort-object -Property Name

但它只从一个作业中吐出数据(有 5 个)。我假设这是因为 foreach 循环中的一些逻辑错误,但我没有看到它。有人可以帮忙吗?

根据 4c74356b41 的评论

foreach($backupJobObject in $backupJobObjects) {
        $MyObject = New-Object PSObject -Property @{ Name = $backupJobObject.Name }
        $Masterlist += $MyObject    
}

最后一个 foreach 循环应该是这样的