Quick Host Profile Reports

Today I needed to grab some quick information on my hosts, which hosts had host profiles enabled, if they were compliant and if not what where the issues ?

With the below script I was easily able to grab this information, as can be seen in the screenshot below:

image

The Script

$HPDetails = @()
Foreach ($VMHost in Get-VMHost) {
	$HostProfile = $VMHost | Get-VMHostProfile
	if ($VMHost | Get-VMHostProfile) {
		$HP = $VMHost | Test-VMHostProfileCompliance
		If ($HP.ExtensionData.ComplianceStatus -eq "nonCompliant") {
			Foreach ($issue in ($HP.IncomplianceElementList)) {
				$Details = "" | Select VMHost, Compliance, HostProfile, IncomplianceDescription
				$Details.VMHost = $VMHost.Name
				$Details.Compliance = $HP.ExtensionData.ComplianceStatus
				$Details.HostProfile = $HP.VMHostProfile
				$Details.IncomplianceDescription = $Issue.Description
				$HPDetails += $Details
			}
		} Else {
			$Details = "" | Select VMHost, Compliance, HostProfile, IncomplianceDescription
			$Details.VMHost = $VMHost.Name
			$Details.Compliance = "Compliant"
			$Details.HostProfile = $HostProfile.Name
			$Details.IncomplianceDescription = ""
			$HPDetails += $Details
		}
	} Else {
		$Details = "" | Select VMHost, Compliance, HostProfile, IncomplianceDescription
		$Details.VMHost = $VMHost.Name
		$Details.Compliance = "No profile attached"
		$Details.HostProfile = ""
		$Details.IncomplianceDescription = ""
		$HPDetails += $Details
	}
}
$HPDetails

3 thoughts on “Quick Host Profile Reports

  1. xav197

    Thank you Alan!
    We are running vsphere 4.1 at my work.
    In some case we do not see the HostProfile name and i get a “NonCompliant” in the column Compliance. To fix that, I had to replace the following line:

    $Details.HostProfile = $HP.VMHostProfile

    by:

    if ($HP.VMHostProfile -eq $null) {$Details.HostProfile = $HostProfile.Name}
    else {$Details.HostProfile = $HP.VMHostProfile}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.