hi dev's,
i have 2 clusters with ESX Hosts.
Now I need to get the number of host in each cluster.
My Quick&Dirty workaround is very slow!
First i get all Clusters in Environment, then the reading the Host Information's and last the Count of the Hosts... In result ~120Sec!! !http://communities.vmware.com/images/emoticons/sad.gif!
is there an other option to get this information?
--stony007_de
Hi,
You can use this piece of code to get the number of hosts in a cluster:
(Get-VMHost -Location myCluster).Count
Is this faster than your solution?
Regards,
Nedko Nedev
PowerCLI Development Team
Nedko,
That code doesn't work if the cluster is empty or contains just one host.
You need to use array subexpression for this
@(Get-VMHost -Location myCluster).Count
Cheers,
Arnim
Good point! :smileyblush:
Regards,
Nedko Nedev
PowerCLI Development Team
The next script gives the number of hosts per cluster in a different way. It works fast but it needs PowerCLI v4.1.
Get-Cluster | ForEach-Object { $Report = "" | Select-Object -Property Cluster,HostsCount $Report.Cluster = $_.Name $Report.HostsCount = $_.ExtensionData.Host.Count $Report }
You can also do this in a oneliner:
Get-Cluster | Select-Object Name,@{N="HostsCount";E={$_.ExtensionData.Host.Count}}
Regards, Robert