Count of powered-on VMs by host or datastore

Via One Liner: How many VMs ? | Virtu-Al.Net.

If you have an environment with a lot of powered-off VMs, you may only want a count of powered-on VMs per host, instead of a count of the total number of VMs per host:

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

To get a count of powered-on VMs for a datastore:

get-datastore linked_clones | Get-VM | where {$_.powerstate -eq "poweredon"} | measure-object