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):


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 $ -RunAsync}
        $BaselineCompliance += Get-Baseline -Name $NJBaseline | Get-Compliance -Entity $vmhost
        $SingleLine = "($vmhost).Name" + "($BaseLineCompliance).Status"   
        #{$statuses += Get-Compliance -Entity $}
        #{Get-Compliance -Entity $}

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.



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) {
        VMHost             = $vmhost.Name
        BaseLineCompliance = (Get-Baseline -Name $NJBaseline | Get-Compliance -Entity $vmhost).Status