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
Production Cluster 2
Production Cluster 7
Production Cluster 8
Production Cluster 22
Production Cluster 16
Production Cluster 31
Production Cluster 24
Production Cluster 27
DMZ Production Cluster 21
DMZ Production Cluster 27
Test Cluster 4
Test Cluster 8
Test Cluster

18 thoughts on “One Liner: How many VMs ?”

  1. to get VMs from cluster use this
    get-cluster | Get-VM | Where-Object {$_.PowerState -eq “PoweredOn”} | Measure-Object

  2. hi all,

    i am wondering if anyone here can help, i am after a script that give me VM name from window DNS name. for example i know the windows guest (DNS) name but want to find the VM for that in vmware.


  3. Need a script to search a set of hosts for a particular VM name and then power that VM on.

    My VCenter is a VM. I have a case where I’ve got to shut the entire enviroment down and then power the enviroment back on. I’d like to script searching each host to find the VCenter server and then when it’s found power that VM on.

    Any ideas?

  4. Get-VMHost | Select @{N=”Cluster”;E={Get-Cluster -VMHost $_}}, Name, @{N=”NumVM”;E={($_ | Get-VM | where {$_.powerstate -eq “poweredon”}).Count}} | Sort Clu
    ster, Name

  5. i am looking for script to do the flowing
    1-count how many linx,,windows,etc on each cluster
    2- only powered on vm


  6. @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

  7. 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?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.