Thanks for you additions. It is a usefull script now.
To prevent the Test-VMHostProfileCompliance cmdlet from outputting red warning messages for hosts that don't have a host profile you can add -ErrorAction:SilentlyContinue to that line. if ($var -ne $null) is the same as if ($var) and is a bit shorter.
foreach ($VMHostin (Get-VMHost)) { $Compliance=Test-VMHostProfileCompliance-VMHost$VMHost-UseCache-ErrorAction:SilentlyContinue $AttachedProfile=Get-VMHostProfile-entity$VMHost if ($Compliance) { $ComplianceStatus=$Compliance.ExtensionData.ComplianceStatus } elseif ($AttachedProfile) { $ComplianceStatus="Compliant" } else { $ComplianceStatus="No Profile Attached!" } New-Object-TypeNamePSObject-Property @{ VMhost =$VMHost.name ComplianceStatus =$ComplianceStatus } }