I use the following in an ESXi patch script:
$vCluster is the cluster that's being patched
$baseline is a single baseline that has a beginning/end date. keeps all hosts in different clusters sync'd, we have 160 hosts, so sometimes new patches are released during our patch runs.
#list compliant/noncompliant hosts
#Test-Compliance -Entity $vCluster -UpdateType HostPatch > $null
Try {
$Compliant_hosts = (Get-Cluster -Name $vCluster | Get-vmHost | Sort-Object | Get-Compliance -Baseline $Baselines | Where-Object { $_.Status -eq 'Compliant' }).Entity.Name
$nonCompliant_hosts = (Get-Cluster -Name $vCluster | Get-vmHost | Sort-Object | Get-Compliance -Baseline $Baselines | Where-Object { $_.Status -ne 'Compliant' }).Entity.Name
}
Catch {
$ErrorMessage = $_.Exception.Message
Write-Error $ErrorMessage
exit_stage_left
}
-------------------------------------------