One Liner: How many VMs ?
Ever wondered how many VM’s you have on each Host? You could manually check it or then again you could let powershell do the work for you:
Get-VMHost | Select @{N=“Cluster“;E={Get-Cluster -VMHost $_}}, Name, @{N=“NumVM“;E={($_ | Get-VM).Count}} | Sort Cluster, Name | Export-Csv -NoTypeInformation c:\clu-host-numvm.csv
Sample Output:
| Cluster | Name | NumVM |
| CLUSTER1 | ESXH01.virtu-al.net | 12 |
| CLUSTER1 | ESXH02.virtu-al.net | 5 |
| CLUSTER1 | PRODESXH22.virtu-al.net | 6 |
| CLUSTER1 | PRODESXH24.virtu-al.net | 11 |
| CLUSTER1 | PRODESXH25.virtu-al.net | 19 |
| CLUSTER1 | PRODESXH26.virtu-al.net | 14 |
| Production Cluster | PRODESXH10.virtu-al.net | 2 |
| Production Cluster | PRODESXH11.virtu-al.net | 7 |
| Production Cluster | PRODESXH12.virtu-al.net | 8 |
| Production Cluster | PRODESXH15.virtu-al.net | 22 |
| Production Cluster | PRODESXH16.virtu-al.net | 16 |
| Production Cluster | PRODESXH17.virtu-al.net | 31 |
| Production Cluster | PRODESXH18.virtu-al.net | 24 |
| Production Cluster | PRODESXH19.virtu-al.net | 27 |
| DMZ Production Cluster | PRODESXH20.virtu-al.net | 21 |
| DMZ Production Cluster | PRODESXH21.virtu-al.net | 27 |
| Test Cluster | PRODESXH23.virtu-al.net | 4 |
| Test Cluster | PRODESXH13.virtu-al.net | 8 |
| Test Cluster | PRODESXH14.virtu-al.net |
Vote for Freedom vote for me (please) Unofficial Online VMware User Group #2











I replaced Export-Csv -NoTypeInformation c:\clu-host-numvm.csv
by Out-GridView looks great, cool script
Oh to be using V2 ! Im still on V1 here, nice one though.
How about listing the number of VMs per Resource Pool?
Thanks.
how can we extend this to get the templates as well
Thanks
@Kayser Soze
@utester12
Both answered here: http://www.virtu-al.net/2009/06/25/powercli-more-one-liners/
Thanks for the idea !
Thanks
For some reason this doesn’t work for hosts that have only one VM on them. The number of VMs in that case shows blank, as if there were no VMs at all on the host.
Is there a workaround?
Thanks
@Mike
My Fault, I didn’t make sure the results were always an array so the count didn’t work if it was 1, try this:
Get-VMHost | Select @{N=”Cluster”;E={Get-Cluster -VMHost $_}}, Name, @{N=”NumVM”;E={@($_ | Get-VM).Count}} | Sort Cluster, Name | Export-Csv -NoTypeInformation c:\clu-host-numvm.csv
[...] my previous post where we counted how many VMs were on each host and the cluster they were in I was asked a couple [...]