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
LucD
Leadership
Leadership

You have to be a bit more explicit on what you want.

- find the attached hostprofile per ESXi node is simple

Get-VMHost | Select Name,@{N='HostProfile';E={(Get-VMHostProfile -Entity $_).Name}}

- listing the content of a HostProfile is rather difficult, since the structure of a HostProfile is not public

- not sure what you mean by issues?


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot

Sure, LucD I mean host profile not compliant this is my issue Smiley Happy

0 Kudos
LucD
Leadership
Leadership

You mean like this?

Get-VMHost | Select Name,

    @{N='Host Profile';E={(Get-View -Id $_.ExtensionData.ComplianceCheckResult.Profile  -Property Name).Name}},

    @{N='Compliance';E={$_.ExtensionData.ComplianceCheckResult.ComplianceStatus}},

    @{N='Compliance Check';E={$_.ExtensionData.ComplianceCheckResult.CheckTime}}


If a compliance check has errors, you can run something like this

Get-VMHost -PipelineVariable esx |

ForEach-Object -Process {

    $esx.ExtensionData.ComplianceCheckResult.Failure |

    Select @{N='VMHost';E={$esx.Name}},

    @{N='Host Profile';E={(Get-View -Id $esx.ExtensionData.ComplianceCheckResult.Profile  -Property Name).Name}},

    @{N='Compliance';E={$esx.ExtensionData.ComplianceCheckResult.ComplianceStatus}},

    @{N='Compliance Check';E={$esx.ExtensionData.ComplianceCheckResult.CheckTime}},

    FailureType,

    @{N='Message';E={$_.Message.Message}}

}


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot

I have created the below script unfortunately no output

# vCenter Login

    $vCUser="Admin"

    $vCPass="pASS'"

# LIST OF vCenters

    $vCenterIP = "vcenter1","vcenter2"

foreach ($IPAddress in $vCenterIP){

# Connection to vCenter

    Connect-VIServer $IPAddress -User $vCUser -Password $vCPass -port 443

}

#Variables

    $Date = Get-Date

    $Datefile = ( Get-Date ).ToString("yyyy-MM-dd-hhmmss")

    $ErrorActionPreference = "SilentlyContinue"

# Variable to change

    $CreateCSV= "yes"

    $GridView = "no"

    $FileCSV = New-Item -Type File -Path ".\Host_Profile_$datefile.csv"

    Write-Host "Gathering Host Profile Information"

#Output

if ($GridView -eq "yes") {

    $report | Out-GridView

}

$report = Get-VMHost -PipelineVariable esx |

ForEach-Object -Process {

    $esx.ExtensionData.ComplianceCheckResult.Failure |

    Select @{N='VMHost';E={$esx.Name}},

    @{N='Host Profile';E={(Get-View -Id $esx.ExtensionData.ComplianceCheckResult.Profile  -Property Name).Name}},

    @{N='Compliance';E={$esx.ExtensionData.ComplianceCheckResult.ComplianceStatus}},

    @{N='Compliance Check';E={$esx.ExtensionData.ComplianceCheckResult.CheckTime}},

    FailureType,

    @{N='Message';E={$_.Message.Message}}

}

if ($CreateCSV -eq "yes") {

    $report | Export-Csv -LiteralPath $FileCSV -NoTypeInformation -UseCulture

}

#Disconnect session from VC

Disconnect-VIserver -Confirm:$false

0 Kudos
LucD
Leadership
Leadership

Do you have HostProfiles attached to one or more of your ESXi nodes?

Did you do a Compliance check on those ESXi nodes?


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot

Yes there's HostProfiles attached as per the confirmation that I got Smiley Happy

for that reason I'm trying to get thes info via script by checking attached host profile and compliance

0 Kudos
LucD
Leadership
Leadership

The script only shows the 'issues' as you requested originally.
If there are no compliance issues, nothing is shown.


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot

Opps then for sure I'm doing something wrong

because from vcenter I'm able to see a lot of host not compliant Smiley Sad

0 Kudos
LucD
Leadership
Leadership

Did you try the script I posted, without your additions?

You will have to connect to a vCenter manually before running it.


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

0 Kudos
LucD
Leadership
Leadership

Give this version a try.

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

    }

} | 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

Thanks LucD

the output show only VMHost, the other details are empty

0 Kudos
LucD
Leadership
Leadership

I get the same result for all ESXi nodes that do not have a HostProfile attached.
The ESXi nodes that do have a HostProfile attached show at least the HostProfile name


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot

Perfect thanks LucD Smiley Happy Smiley Happy

I will checked other hosts and I will keep you posted

0 Kudos
SCharchouf
Hot Shot
Hot Shot

I just verified and the Host Profile is attached to Cluster not the ESXi Node and I believe for that reason the output are empty

0 Kudos
LucD
Leadership
Leadership

Ok, then try with 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

    }

} | 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

SCharchouf
Hot Shot
Hot Shot

Now I get "HostProfile" information but the below details are still emplty

StatusCheckTimeFailTypeExpressionFailMessage

:smileyblush::smileyblush:

0 Kudos
LucD
Leadership
Leadership

I see the same when no Compliance check was run on that ESXi node.


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

0 Kudos
SCharchouf
Hot Shot
Hot Shot

Strange, because I checked the compliance from vCenter twice and the report still show empty info

not sure what happend Smiley Sad

0 Kudos
LucD
Leadership
Leadership

What does it say in the Web Client for the Host Profile Status?

hp-status.png


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

0 Kudos