$allvms = @()
$vms = Get-Vm server1, server2, server3
$start = "12/15/2013 06:00 PM"
$FInish = "12/15/2013 11:59 PM"
$metrics = "cpu.usage.average","mem.usage.average"
$stats = Get-Stat -Entity $vms -Start $start -Finish $Finish -Stat $metrics
$stats | Group-Object -Property {$_.Timestamp.Day},{$_.Entity.Name} | %{
$vmstat = "" | Select VmName, Day, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin
$vmstat.VmName = $_.Values[1]
$vmstat.Day = $_.Group[0].Timestamp.Date
$cpu = $_.Group | where {$_.MetricId -eq "cpu.usage.average"} | Measure-Object -Property value -Average -Maximum -Minimum
$mem = $_.Group | where {$_.MetricId -eq "mem.usage.average"} | Measure-Object -Property value -Average -Maximum -Minimum
$vmstat.CPUMax = [int]$cpu.Maximum
$vmstat.CPUAvg = [int]$cpu.Average
$vmstat.CPUMin = [int]$cpu.Minimum
$vmstat.MemMax = [int]$mem.Maximum
$vmstat.MemAvg = [int]$mem.Average
$vmstat.MemMin = [int]$mem.Minimum
$allvms += $vmstat
}
$allvms