Skip to content

VirtuallyThatGuy

Anything VMware , PowerCLI, PowerShell, Automation and some Windows

Menu
  • Home
  • PowerCLI
  • VMware
  • Automation
  • Windows
  • About
Menu

VMware Host Profile Compliance Checks Using Powercli – VirtuallyThatGuy

Posted on 15 May 20196 December 2022 by VirtuallyThatGuy

Welcome to VirtuallyThatGuy – today we are going to discuss how to quickly check host profile compliance and export the results to a CSV. You can use windows task scheduler to auto schedule this and even get the csv to be sent via an email. I’m sure most of you know how to schedule a powershell script job in windows. I will try to cover this in a later post.

## Start-Transcript
Start-Transcript -Path C:\scripts\HostProfileComplianceChecks.txt 

## Set Variables

## Connect to vCenters 
Connect-VIServer uk3p-vc01.lab.local, ntcp-vc01.lab.local -User "rboadi@lab.local" -Password "StandUpIfYouHateTottenham"


$HostProfileDetails = @()
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
            $HostProfileDetails += $Details
         }
      } Else {
         $Details = "" | Select VMHost, Compliance, HostProfile, IncomplianceDescription
         $Details.VMHost = $VMHost.Name
         $Details.Compliance = "Compliant"
         $Details.HostProfile = $HostProfile.Name
         $Details.IncomplianceDescription = ""
         $HostProfileDetails += $Details
      }
   } Else {
      $Details = "" | Select VMHost, Compliance, HostProfile, IncomplianceDescription
      $Details.VMHost = $VMHost.Name
      $Details.Compliance = "No profile attached"
      $Details.HostProfile = ""
      $Details.IncomplianceDescription = ""
      $HostProfileDetails += $Details
   }
}
## Generate the report and export to a CSV 

$HostProfileDetails | Export-Csv -Path C:\scripts\HostProfileComplianceChecks.csv -NoTypeInformation


Stop-Transcript

## End of Script 

## Start-Transcript

Start-Transcript​​ -Path​​ C:\scripts\HostProfileComplianceChecks.txt​​ 

 

## Set Variables

 

## Connect to vCenters​​ 

Connect-VIServer​​ uk3p-vc01.lab.local,​​ ntcp-vc01.lab.local​​ -User​​ "rboadi@lab.local"​​ -Password​​ "StandUpIfYouHateTottenham"

 

 

$HostProfileDetails​​ =​​ @()

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

 ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ $HostProfileDetails​​ +=​​ $Details

 ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ }

 ​​ ​​ ​​ ​​ ​​​​ }​​ Else​​ {

 ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ $Details​​ =​​ ""​​ |​​ Select​​ VMHost,​​ Compliance,​​ HostProfile,​​ IncomplianceDescription

 ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ $Details.VMHost​​ =​​ $VMHost.Name

 ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ $Details.Compliance​​ =​​ "Compliant"

 ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ $Details.HostProfile​​ =​​ $HostProfile.Name

 ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ $Details.IncomplianceDescription​​ =​​ ""

 ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ $HostProfileDetails​​ +=​​ $Details

 ​​ ​​ ​​ ​​ ​​​​ }

 ​​ ​​​​ }​​ Else​​ {

 ​​ ​​ ​​ ​​ ​​​​ $Details​​ =​​ ""​​ |​​ Select​​ VMHost,​​ Compliance,​​ HostProfile,​​ IncomplianceDescription

 ​​ ​​ ​​ ​​ ​​​​ $Details.VMHost​​ =​​ $VMHost.Name

 ​​ ​​ ​​ ​​ ​​​​ $Details.Compliance​​ =​​ "No profile attached"

 ​​ ​​ ​​ ​​ ​​​​ $Details.HostProfile​​ =​​ ""

 ​​ ​​ ​​ ​​ ​​​​ $Details.IncomplianceDescription​​ =​​ ""

 ​​ ​​ ​​ ​​ ​​​​ $HostProfileDetails​​ +=​​ $Details

 ​​ ​​​​ }

}

## Generate the report and export to a CSV​​ 

 

$HostProfileDetails​​ |​​ Export-Csv​​ -Path​​ C:\scripts\HostProfileComplianceChecks.csv​​ -NoTypeInformation

 

 

Stop-Transcript

 

## End of Script​​ 

​​ 

 

VmhostComplianceHostProfileIncomplianceDescription
UK3P-ESXi01.lab.localcompliantUK3P-Prod-6.7-MasterProfile 
UK3P-ESXi02.lab.localnoncompliantUK3P-Prod-6.7-MasterProfileNTP configuration doesn’t match the specification 
UK3P-ESXi02.lab.localnoncompliantUK3P-Prod-6.7-MasterProfileDNS configuration doesn’t match the specification 
UK3P-ESXi02.lab.localnoncompliantUK3P-Prod-6.7-MasterProfileIPV6 vmknic gateway configuration doesn’t match specification
UK3P-ESXi03.lab.local no profile attached 

5 thoughts on “VMware Host Profile Compliance Checks Using Powercli – VirtuallyThatGuy”

  1. anthony says:
    16 January 2020 at 18:12

    nice!

    Reply
  2. wolvverine says:
    7 July 2020 at 18:42

    with details:

    $HostProfileDetails = @()

    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,ProfileInstance,ComparisonIdentifier,HostValue,ProfileValue
    $HPFailrues = $HP.ExtensionData.Failure| Where {$_.ExpressionName -eq $issue.PropertyName} | select -ExpandProperty FailureValues
    $Details.VMHost = $VMHost.Name
    $Details.Compliance = $HP.ExtensionData.ComplianceStatus
    $Details.HostValue = “$($HPFailrues.HostValue)”
    $Details.ProfileValue = “$($HPFailrues.ProfileValue)”
    $Details.ProfileInstance = “$($HPFailrues.ProfileInstance)”
    $Details.ComparisonIdentifier = “$($HPFailrues.ComparisonIdentifier)”
    $Details.HostProfile = $HP.VMHostProfile
    $Details.IncomplianceDescription = $Issue.Description
    $HostProfileDetails += $Details
    }
    } Else {
    $Details = “” | Select VMHost,Compliance,HostProfile,IncomplianceDescription,ProfileInstance,ComparisonIdentifier,HostValue,ProfileValue
    $Details.VMHost = $VMHost.Name
    $Details.Compliance = “Compliant”
    $Details.HostProfile = $HostProfile.Name
    $Details.IncomplianceDescription = “”
    $HostProfileDetails += $Details
    }
    } Else {
    $Details = “” | Select VMHost,Compliance,HostProfile,IncomplianceDescription,ProfileInstance,ComparisonIdentifier,HostValue,ProfileValue
    $Details.VMHost = $VMHost.Name
    $Details.Compliance = “No profile attached”
    $Details.HostProfile = “”
    $Details.IncomplianceDescription = “”
    $HostProfileDetails += $Details
    }
    }

    Reply
    1. VirtuallyThatGuy says:
      7 August 2020 at 10:00

      thanks buddy for contributing to the community

      Reply
  3. Shyam says:
    23 July 2021 at 10:12

    Thanks. Love your password 🙂

    Reply
    1. VirtuallyThatGuy says:
      23 July 2021 at 10:43

      You know where my football allegiance are with such a password lol

      Reply

Leave a Reply to VirtuallyThatGuy Cancel reply

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

When autocomplete results are available use up and down arrows to review and enter to go to the desired page. Touch device users, explore by touch or with swipe gestures.

Recent Posts

  • vROps: Management Pack Troubleshooting
  • Windows AD {Active Directory} (PowerShell) samples
  • Migrate VMs Between vCentres Using Powershell or PowerCLI
  • Set VM Tools to Update Automatically on VM Reboot using powershell
  • Windows Administrator Must Have Powershell Commands

Recent Comments

  • JB on Script: How to get VM with Tag Assignment and export results to csv using PowerCLI or Powershell
  • DL on How to change VCSA root password and bypass BAD PASSWORD: it is based on a dictionary word for vCenter VCSA root account warning
  • 360coolp on How to change VCSA root password and bypass BAD PASSWORD: it is based on a dictionary word for vCenter VCSA root account warning
  • Yogesh on ESXi 8.x, 7.x, 6.x Service sfcbd-watchdog Not Running / Fails to Start – VirtuallyThatGuy
  • VirtuallyThatGuy on ESXi 8.x, 7.x, 6.x Service sfcbd-watchdog Not Running / Fails to Start – VirtuallyThatGuy

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017

Categories

  • Automation
  • PowerCLI
  • VMware
  • Windows
© 2025 VirtuallyThatGuy | Powered by Superbs Personal Blog theme