VMware Cloud Community
SCharchouf
Hot Shot
Hot Shot

Host Profile issues

I'm trying to find a way using  PowerCLI in order to get all host profil issues, configuration and attached, is that possible?

31 Replies
SCharchouf
Hot Shot
Hot Shot

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership

That is the Host Profile itself, I mean via the ESXi node - Configuration - Host Profile


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
SCharchouf
Hot Shot
Hot Shot

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership

I checked the script again, and indeed, when the HostProfile is Compliant, it wasn't reported.

Try this version

Get-VMHost -PipelineVariable esx |

ForEach-Object -Process {

    $obj = New-Object -TypeName PSObject -Property @{

        VMHost = $esx.Name

        HostProfile = ''

        Status = ''

        CheckTime = ''

        FailType = ''

        Expression = ''

        FailMessage = ''

    }

    $hp = Get-VMHostProfile -Entity $esx

    if($hp){

        $obj.HostProfile = $hp.Name

        if($esx.ExtensionData.ComplianceCheckState){

            $obj.Status = $esx.ExtensionData.ComplianceCheckState.State

            $obj.CheckTime = $esx.ExtensionData.ComplianceCheckState.CheckTime

            if($esx.ExtensionData.ComplianceCheckState.State -ne [VMware.Vim.ComplianceResultStatus]::compliant){

                $esx.ExtensionData.ComplianceCheckResult.Failure |

                ForEach-Object -Process {

                    $objCopy = $obj | ConvertTo-Json | ConvertFrom-Json

                    $obj.FailType = $_.FailureType

                    $obj.Expression = $_.Expression

                    $obj.FailMessage = $_.Message.Message

                    $obj

                    $obj = $objCopy | ConvertTo-Json | ConvertFrom-Json

                }

            }

            else{

                $obj

            }

        }

        else{

            $obj

        }

    }

    else{

        $obj

    }

} | Select -Property VMHost,HostProfile,Status,CheckTime,FailType,Expression,FailMessage |

Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
SCharchouf
Hot Shot
Hot Shot

Tested on 3 differents vCenter the got the same results, still empty

StatusCheckTimeFailTypeExpressionFailMessage
0 Kudos
LucD
Leadership
Leadership

Then I give up.

The last version gives me also the Status and CheckTime for the ESXi nodes that are Compliant.
I just tested again (on vSphere 7).

2020-05-16_22-24-52.png


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

LucD
Leadership
Leadership

Wait a minute, the properties I'm using were only introduced in API 6.7.
Which vSphere version are you using?

api67.jpg


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
SCharchouf
Hot Shot
Hot Shot

version 6

0 Kudos
LucD
Leadership
Leadership

Ok, in that case try this pre-API  6.7 version

$si = Get-View ServiceInstance

$hpMgr = Get-View -Id $si.Content.HostProfileManager

$hpCompMgr = Get-View -Id $si.Content.ComplianceManager


Get-VMHost -PipelineVariable esx |

ForEach-Object -Process {

    $obj = New-Object -TypeName PSObject -Property @{

        VMHost = $esx.Name

        HostProfile = ''

        Status = ''

        CheckTime = ''

        FailType = ''

        Expression = ''

        FailMessage = ''

    }

    $hpMoRef = $hpMgr.FindAssociatedProfile($esx.Id)

    if($hpMoRef){

        $hp = Get-View -Id $hpMoRef

        $obj.HostProfile = $hp.Name

        $compliance = $hpCompMgr.QueryComplianceStatus($hp.MoRef,$esx.Id)

        $obj.Status = $compliance[0].ComplianceStatus

        $obj.CheckTime = $compliance[0].CheckTime

        if($compliance[0].Failure){

                $compliance[0].Failure |

                ForEach-Object -Process {

                    $objCopy = $obj | ConvertTo-Json | ConvertFrom-Json

                    $obj.FailType = $_.FailureType

                    $obj.Expression = $_.ExpressionName

                    $obj.FailMessage = $_.Message.Message

                    $obj

                    $obj = $objCopy | ConvertTo-Json | ConvertFrom-Json

                }

        }

        else{

            $obj

        }

    }

    else{

        $obj

    }

} | Select -Property VMHost,HostProfile,Status,CheckTime,FailType,Expression,FailMessage


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

SCharchouf
Hot Shot
Hot Shot

Thanks LucD much appreciated Smiley Happy

it's working now Smiley Happy

second step for this good script is to run it as a scheduled task with daily report (best option one excel file with multiple sheet)

is that possible?

0 Kudos
LucD
Leadership
Leadership

I propose to create a new thread for that question.
Specify which kind of task scheduler you intend to use (Windows, Linux ...)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

SCharchouf
Hot Shot
Hot Shot

Sure Smiley Happy

0 Kudos