Compare ESX configurations with Powershell
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
12 Responses to Compare ESX configurations with Powershell
Tags
Active Directory API bind order cleanup cluster CPU Custom Fields datastores description device management directory tree errors Event Log file name filter Fun function HA IT known issues License Server LUN multipath NIC objects Oneliner portgroups PowerCLI PowerShell profile recursive Registry Scripts security session share snapshots SQL Stat VI Toolkit VMware vSphere WMI WSUS ZenArchives
- July 2012
- July 2011
- February 2011
- January 2011
- December 2010
- May 2010
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008





Very nice, your on fire lately !
[...] 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 [...]
[...] posted a great script. It will compare configuration items between a given set of hosts. This can especially come in [...]
[...] to do manual configuration control on the cheap could take a look at Hugo Peeters scripts on comparing ESX configurations with powershell.
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
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
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
Hugo,
How do I use these functions with the VI-Toolkit?
Hugo (very much a beginner with PowerShell)
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
Thanks for that, I’ll give that a go.
Hugo
thanks a lot!
great information! thanks!
http://www.vmwarescripting.com/
[...] showed you before how to compare the datastores for two ESX Servers using the VI Toolkit. But ideally, one would like [...]