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

18 thoughts on “One Liner: How many VMs ?

  1. Mohammed Abdul Hadi Siddiqui

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

  2. TA

    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.

    Regards
    TA

  3. Christopher Eakin

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

    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. Pingback: Count of powered-on VMs by host | VirtIRL

  6. emad

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

    Thanks

  7. Pingback: PowerCLI: More One Liners « Virtu-Al

  8. Virtu-Al

    @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

  9. Mike

    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

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.