VMware Cloud Community
daphnissov
Immortal
Immortal
Jump to solution

Advanced Setting comparator function?

/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?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try this one.

It produces 2 reports:

  1. Settings that are not present on all the ESXi nodes in the cluster
  2. Settings with different values on the ESXi nodes

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.

#requires -modules ImportExcel

$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

View solution in original post

6 Replies
LucD
Leadership
Leadership
Jump to solution

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.

$clusterName = 'MyCluster'

$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

daphnissov
Immortal
Immortal
Jump to solution

Thanks, this seems like a good start! What'd be the optimal way to loop through all the advanced settings in this fashion?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

daphnissov
Immortal
Immortal
Jump to solution

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.

  1. Get all advanced settings (key and value) from all hosts in a given cluster.
  2. Compare all keys (names) from all results.
  3. Any keys not common to all hosts would be displayed independently along with their values and the host(s) to which they applied.
  4. Compare all values from all results.
  5. Repeat #3 but for values.

Optionally, another possible branch of logic looks something like this:

  1. Get all advanced settings from all hosts.
  2. For any keys which are not common amongst all hosts, display the keys which do not occur on all hosts (along with their values).
  3. For everything else where all keys are the same but values are different (where N number of hosts do not produce M number of values), print all key/value pair for all hosts showing key, value, and host.

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.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try this one.

It produces 2 reports:

  1. Settings that are not present on all the ESXi nodes in the cluster
  2. Settings with different values on the ESXi nodes

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.

#requires -modules ImportExcel

$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

daphnissov
Immortal
Immortal
Jump to solution

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!

0 Kudos