Your script is ok, but instead of calling Get-Stat 500+ times, I would only call it once with all 500+ VMs
And then use the Group-Object cmdlet to split the results per VM.
Something like this
$vms = Get-VM
$now = Get-Date
Get-Stat -Entity $vms -Stat cpu.usage.average -Start $now.AddHours(-4) |
Group-Object -Property {$_.Entity.Name} | %{
$avgCpu = $_.Group | Where {$_.Value -ne 0} | Measure-Object -Property Value -Average |
Select -ExpandProperty Average
if($avgCpu -gt 80) {$_.Name}
}
You will have to change the Get-VM to get the 500+ VMs you want to monitor