I'm trying to find a way using PowerCLI in order to get all host profil issues, configuration and attached, is that possible?
That is the Host Profile itself, I mean via the ESXi node - Configuration - Host Profile
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I checked the script again, and indeed, when the HostProfile is Compliant, it wasn't reported.
Try this version
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
Tested on 3 differents vCenter the got the same results, still empty
Status | CheckTime | FailType | Expression | FailMessage |
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).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Wait a minute, the properties I'm using were only introduced in API 6.7.
Which vSphere version are you using?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
version 6
Ok, in that case try this pre-API 6.7 version
$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
Thanks LucD much appreciated
it's working now
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?
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
Sure