Trying to create a report capturing data from different commands

I am trying to create VMHost report that will report is a system is compliant with specific identified settings. Initially, I would like to report to generate on screen and be exportable to CSV. I would each line to represent a single host and the associated status. Here is visually I would like to output (simplified to two categories, rather than the 30 I will have in the end):

VMHost,BaseLineCompliance
ESX1,Compliant,
ESX2,Compliant,

Here is what I have come up with so far:


Connect-VIServer -Server $vc -Credential $Credential

$NJBaseline = "ESXi_6.7_Q3_Q4_2020"
$BaseLineCompliance = @()

#Get all VMHosts and retrieve the compliance statuses

$vmhosts = Get-VMHost
    
    ForEach ($vmhost in $vmhosts)
        #{Test-Compliance -Entity $vmhost.name -RunAsync}
        {
        $vmhost.Name
        $BaselineCompliance += Get-Baseline -Name $NJBaseline | Get-Compliance -Entity $vmhost
        $BaseLineCompliance.Status 
        $SingleLine = "($vmhost).Name" + "($BaseLineCompliance).Status"   
        }
        #{$statuses += Get-Compliance -Entity $vmhost.name}
        #{Get-Compliance -Entity $vmhost.name}

My output for the $SingleLine variable looks like this:

(esxi1).Name(VMware.VumAutomation.Types.BaselineCompliance VMware.VumAutomation.Types.BaselineCompliance VMware.VumAutomation.Types.BaselineCompliance VMware.VumAutomation.Types
.BaselineCompliance VMware.VumAutomation.Types.BaselineCompliance

Any assistance is greatly appreciated. Thanks in advance.

~Ed

Ed,

Welcome to the forums.

If I got it right this should be all you need:

Connect-VIServer -Server $vc -Credential $Credential
$NJBaseline = 'ESXi_6.7_Q3_Q4_2020'
$vmhosts = Get-VMHost
ForEach ($vmhost in $vmhosts) {
    [PSCustomObject]@{
        VMHost             = $vmhost.Name
        BaseLineCompliance = (Get-Baseline -Name $NJBaseline | Get-Compliance -Entity $vmhost).Status 
    }
}