Thanks! I made a few additions to the sample which will also check if no profile is attached:
foreach
($VMHostin (Get-VMHost)) {
$Compliance=Test-VMHostProfileCompliance-VMHost$VMHost-UseCache
$AttachedProfile=Get-VMHostProfile-entity$VMHost
if ($Compliance-ne$null)
{
$ComplianceStatus=$Compliance.ExtensionData.ComplianceStatus
}
elseif ($AttachedProfile-eq$null)
{
$ComplianceStatus="No Profile Attached!"
}
else
{
$ComplianceStatus="Compliant"
}
New-Object-TypeNamePSObject-Property @{
VMhost
=$VMHost.name
ComplianceStatus
=$ComplianceStatus
}
}