One of the challenges in managing a large VMware Infrastructure is keeping all ESX Servers within a cluster equal. This is essential for having vmotion capabilities and therefore essential for a solid HA configuration. I have showed you earlier how to add the LUN Count for each ESX Server to your VI Client. This allows you to spot differences quickly. But finding exactly which datastores are missing on which ESX Server can be a bigger challenge.

Here are some small functions that can help you determine where the major differences are.

Comparing datastores:

function Compare-VMHostDatastores
{
param([string]$host1,[string]$host2)
$a = Get-VMHost $host1 | Get-Datastore | %{$_.Name}
$b = Get-VMHost $host2 | Get-Datastore | %{$_.Name}
Compare-Object $a $b
}

Compare-VMHostDatastores esxServer1 esxServer2

InputObject                         SideIndicator
———–                                ————-
esxServer1_Local             <=
esxServer2_Local             =>
DATASTORE_TEST1         =>

And comparing Port Groups:

function Compare-VMHostPortgroups
{
param([string]$host1,[string]$host2)
$a = Get-VirtualPortGroup (Get-VMHost $host1) | %{$_.Name}
$b = Get-VirtualPortGroup (Get-VMHost $host2) | %{$_.Name}
Compare-Object $a $b
}

Compare-VMHostPortgroups esxServer1 esxServer2

InputObject                SideIndicator
———–                      ————-
PortGroup_TEST     <=
Internal                       <=

Maybe you prefer to go the other way around and check to which ESX servers a specific datastore is attached?

function Get-DatastoreHosts
{
param([string]$datastore)
Get-VMHost -Datastore (Get-Datastore $datastore) | Sort Name | %{$_.Name}
}

PS D:Scripts> Get-DatastoreHosts DATASTORE_TEST1

esxServer2
esxServer3

Thank Microsoft for Powershell and the Compare-Object cmdlet!

Hugo

Tagged with:
 

12 Responses to Compare ESX configurations with Powershell

  1. Alan Renouf says:

    Very nice, your on fire lately !

  2. [...] in January 7th, 2009 Published in Management & Automation, Server Hugo posted a great script. It will compare configuration items between a given set of hosts. This can especially come in [...]

  3. Compare specific ESX configuration items « H9Newser’s Blog says:

    [...] posted a great script. It will compare configuration items between a given set of hosts. This can especially come in [...]

  4. [...] to do manual configuration control on the cheap could take a look at Hugo Peeters scripts on comparing ESX configurations with powershell.

  5. Paul says:

    Hi Hugo,

    any idea why when i run this script i only get back my local datastores?

    param([string]$host1,[string]$host2)
    $a = Get-VMHost $host1 | Get-Datastore | %{$_.Name}
    $b = Get-VMHost $host2 | Get-Datastore | %{$_.Name}
    Compare-Object $a $b

    but if i run
    $a = Get-VMHost $host1 | Get-Datastore | %{$_.Name}
    $a

    i get all my datastores?

    cheers

    • admin says:

      Hi Paul,
      Be glad. The local datastores are the only difference between the two hosts. Add the -IncludeEqual switch to the Compare-Object line to show all datastores.
      Hugo

  6. Paul says:

    Hi Hugo,

    I was expecting to get back all my datastores with the ones being equal having a == sign in the SideIndicator. But having read the help on compare-objectshow them.

    thanks for that!

    Paul

  7. Hugo says:

    Hugo,

    How do I use these functions with the VI-Toolkit?

    Hugo (very much a beginner with PowerShell)

  8. admin says:

    Hugo,

    I assume you have Powershell and the VI Toolkit installed. Start the VI Toolkit console (which is essentially Powershell with the VI Toolkit snapin loaded). Connect to Virtual Center using “Connect-VIServer MYVCSERVER”.

    Manually:
    Copy and paste the functions into the window and press enter a few times. Then you can use the functions by typing the name and supplying two host names or a datastore name (see the second quotes for examples). When you close the window, the functions are forgotten.

    Profile:
    Add the functions to your profile in order to have them available every time you open the Powershell / VI Toolkit window. Read this for more info: http://www.peetersonline.nl/index.php/powershell/build-your-own-powershell-universe/

    Hugo

  9. Hugo says:

    Thanks for that, I’ll give that a go.

    Hugo

  10. eric says:

    thanks a lot!

    great information! thanks!

    http://www.vmwarescripting.com/

  11. [...] showed you before how to compare the datastores for two ESX Servers using the VI Toolkit. But ideally, one would like [...]

Leave a Reply