Try changing this line
$stats=Get-Stat-Entity$vms-Stat$metric-Start$start-Finish$finish
to this
$stats=Get-Stat-Entity$vms-Stat$metric-Start$start-Finish$finish-ErrorActionSilentlyContinue
There might be some VMs for which there is no performance data available for the selected period.