/cc LucD
I'm wondering if you (Luc) or anyone else has ever seen or made an ESXi advanced setting comparator function. What I'd like to produce (if no one has done it) is to write a script or function which takes a compute cluster as an input object, loops through all the advanced settings on each host gathering the names of the settings and their values, compares them with all the other hosts, and displays a list of those (either name OR value) which differ from the cluster.
For example, let's say I wanted to ensure that Net.TcpipHeapSize was consistent at 32 across all hosts in a given cluster. I could dump out the settings of each host and line them up in some sort of view to determine that for myself, but what would be much more helpful is if I could just get told "these are the ones which aren't the same" followed by which host(s) are the odd ball and what that devious setting is. Anyone done/seen this done?
Try this one.
It produces 2 reports:
The script uses the ImportExcel module, which allows to write the results to different worksheets in a XLSX
As an alternative you could write the 2 reports to separate CSV files for example.
$clusterName = 'Cluster1'
$fileName = "$clusterName-$(Get-Date -Format 'yyyyMMdd-HHmm').xlsx"
$esx = Get-Cluster -Name $clusterName | Get-VMHost
$settings = Get-AdvancedSetting -Entity $esx | Sort-Object -Property Name
# Settings not present on all ESXi nodes
$settings | Group-Object -Property Name |
where {$_.Count -ne $esx.Count} |
Select Name, @{N = 'Values'; E = {($_.Group | Sort-Object -Property Entity | % {"{0}:{1}" -f $_.Entity, $_.Value}) -join '|'}} |
Export-Excel -Path $fileName -WorksheetName 'Nodes missing' -TitleBold -Title 'Settings not present on all ESXi nodes' -AutoSize
# Settings with different values on ESXi nodes
$settings | Group-Object -Property Name, Value |
where {$_.Count -ne $esx.Count} |
Select @{N = 'Name'; E = {$_.Name.Split(',')[0]}},
@{N = 'Value'; E = {$_.Name.Split(',')[1]}},
@{N = 'Nodes'; E = {$_.Group.Entity -join '|'}} |
Export-Excel -Path $fileName -WorksheetName 'Settings different' -TitleBold -Title 'Settings with different values' -AutoSize -Show
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I did something like that some time ago.
The following example is for one specific advanced setting for a specific cluster.
This can be adapted to loop over all advanced settings.
$advName = 'Net.TcpipHeapSize'
Get-Cluster -Name $clusterName | Get-VMHost |
Get-AdvancedSetting -Name $advName |
Group-Object -Property Value |
Sort-Object -Property Count -Descending |
Select @{N='Setting';E={$advName}},@{N='Value';E={$_.Name}},
@{N='VMHost';E={$_.Group.Entity -join '|' }}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, this seems like a good start! What'd be the optimal way to loop through all the advanced settings in this fashion?
Depends a bit, could there be an ESXi node that has more advanced settings than another?
If yes, we would first need to compile all the advanced settings on all the ESXi nodes.
Then with that list, we could loop, for each each ESXi node, over all the settings.
Would that be a possible situation?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Depends a bit, could there be an ESXi node that has more advanced settings than another?
There could and would be that eventuality, yes.
So, my logic would look something like this. Perhaps some of this could be controlled with parameters.
Optionally, another possible branch of logic looks something like this:
Branch two may be simpler. This is obviously advanced stuff, so what you provided earlier in code is probably simpler, but longterm something like this would be a GREAT tool to have. Very often when doing things like audits and health checks, it's important to know where drift has occurred, and a function or script like this would make that possible.
Try this one.
It produces 2 reports:
The script uses the ImportExcel module, which allows to write the results to different worksheets in a XLSX
As an alternative you could write the 2 reports to separate CSV files for example.
$clusterName = 'Cluster1'
$fileName = "$clusterName-$(Get-Date -Format 'yyyyMMdd-HHmm').xlsx"
$esx = Get-Cluster -Name $clusterName | Get-VMHost
$settings = Get-AdvancedSetting -Entity $esx | Sort-Object -Property Name
# Settings not present on all ESXi nodes
$settings | Group-Object -Property Name |
where {$_.Count -ne $esx.Count} |
Select Name, @{N = 'Values'; E = {($_.Group | Sort-Object -Property Entity | % {"{0}:{1}" -f $_.Entity, $_.Value}) -join '|'}} |
Export-Excel -Path $fileName -WorksheetName 'Nodes missing' -TitleBold -Title 'Settings not present on all ESXi nodes' -AutoSize
# Settings with different values on ESXi nodes
$settings | Group-Object -Property Name, Value |
where {$_.Count -ne $esx.Count} |
Select @{N = 'Name'; E = {$_.Name.Split(',')[0]}},
@{N = 'Value'; E = {$_.Name.Split(',')[1]}},
@{N = 'Nodes'; E = {$_.Group.Entity -join '|'}} |
Export-Excel -Path $fileName -WorksheetName 'Settings different' -TitleBold -Title 'Settings with different values' -AutoSize -Show
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Very cool, LucD! Looks great. Let me test it on a couple of environments with mixed versions to see its results. But thank you for putting this together!