Compare Cluster Datastores with Powershell

I showed you before how to compare the datastores for two ESX Servers using the VI Toolkit. But ideally, one would like to compare all ESX servers in a cluster to ensure VMotion and HA compatibility.
So I started scripting and it turns out to be pretty simple: only 4 lines of code in Powershell! It does the comparison for all your clusters and returns clean little tables with datastores you should investigate.

SCRIPT CODE:

ForEach ($Cluster in (Get-Cluster | Sort Name))
{
$VMHosts = Get-Cluster $Cluster.Name | Get-VMHost
$Datastores = $VMHosts | Get-Datastore
$VMHosts | ForEach {Compare-Object $Datastores ($_ | Get-Datastore)} | ForEach {$_.InputObject} | Sort Name | Select @{N=$Cluster.Name;E={$_.Name}} -Unique | Format-Table
}

SAMPLE OUTPUT:

TEST CLUSTER 1
——————
DATASTORE1
LOCAL01
LOCAL02
LOCAL03

TEST CLUSTER 2
——————
DATASTORE2
DATASTORE3
LOCAL06
LOCAL07
LOCAL08
LOCAL09

Coming very soon: a full-blown script that compares datastores, LUNs and portgroups across your clusters ├índ identifies exactly where the differences are! Stay tuned…

»crosslinked«

2 thoughts on “Compare Cluster Datastores with Powershell”

  1. Pingback: Compare Cluster Datastores with Powershell « H9Newser’s Blog

Leave a Reply