I'm trying to find a way using PowerCLI in order to get all host profil issues, configuration and attached, is that possible?
You have to be a bit more explicit on what you want.
- find the attached hostprofile per ESXi node is simple
- 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
Sure, LucD I mean host profile not compliant this is my issue
You mean like this?
@{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
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
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
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
Yes there's HostProfiles attached as per the confirmation that I got
for that reason I'm trying to get thes info via script by checking attached host profile and compliance
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
Opps then for sure I'm doing something wrong
because from vcenter I'm able to see a lot of host not compliant
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
Give this version a try.
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
Thanks LucD
the output show only VMHost, the other details are empty
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
Perfect thanks LucD
I will checked other hosts and I will keep you posted
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
Ok, then try with 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
}
} | 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
Now I get "HostProfile" information but the below details are still emplty
Status | CheckTime | FailType | Expression | FailMessage |
:smileyblush::smileyblush:
I see the same when no Compliance check was run on that ESXi node.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Strange, because I checked the compliance from vCenter twice and the report still show empty info
not sure what happend
What does it say in the Web Client for the Host Profile Status?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference