DigitalKiller
Contributor
Contributor

Powered On/Off VM count per cluster

Trying to get the number of powered on and powered off VMs by cluster. Getting it for the data center was straight forward:

Connect-VIServer "VI Server"
# Get VM counts
$VMs = Get-View -ViewType VirtualMachine
Write-Host "Powered on : " (@($VMs | Where { $_.Runtime.PowerState -eq "poweredOn" }).Count)
Write-Host "Powered off: " (@($VMs | Where { $_.Runtime.PowerState -eq "poweredOff" }).Count)

But for the cluster, I have only been able to do it by going through each ESX host and getting the numbers and summing. This of course is painfully slow.

Anyone have an efficient way to get the counts of powered on and off VMs for each cluster in virtual center?

Thanks!

0 Kudos
2 Replies
admin
Immortal
Immortal

Try the following:

$vms = Get-Cluster <cluster_name> | Get-VM
write-host "Powered on: " ($vms | where {$_.PowerState -eq "PoweredOn"}).Count
write-host "Powered off: " ($vms | where {$_.PowerState -eq "PoweredOff"}).Count

0 Kudos
DigitalKiller
Contributor
Contributor

That worked perfect. I knew there was a better way!

Thanks!

0 Kudos