Ok, let's start with a simple one.
This will get the values for the past hour for all VMs, and then calculate the average over that hour for all 4 categories.
Note that when you use the Get-Stat cmdlet without specifying any metrics on the Stat parameter, the cmdlet returns a number of metrics by default.
We use the ErrorAction on the Get-Stat to avoid error messages for when there are not statistics available for that VM at the time speficied on the Start parameter.
We call Get-Stat for all VMs in one call, then we use the Group-Object cmdlet to split up the results per VM.
In the object returned by the Group-Object cmdlet we have the key (Name) on which we grouped, and all the values under a property named Group.
On the objects present in Group, we now pull out the objects for specific metrics. Those we average.
We do that in a calculated property on the Select (short for Select-Object) cmdlet.
$vms = Get-VM
$start = (Get-Date).AddHours(-1)
Get-Stat -Entity $vms -Start $start -ErrorAction SilentlyContinue |
Group-Object -Property {$_.Entity.Name} |
Select @{N='VM';E={$_.Name}},
@{N='CPU(%)';E={"{0:N1}" -f ($_.Group | where{$_.MetricId -eq 'cpu.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}},
@{N='Memory(%)';E={"{0:N1}" -f ($_.Group | where{$_.MetricId -eq 'mem.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}},
@{N='Net(KBps)';E={"{0:N2}" -f ($_.Group | where{$_.MetricId -eq 'net.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}},
@{N='Disk(KBps';E={"{0:N2}" -f ($_.Group | where{$_.MetricId -eq 'disk.usage.average'} | Measure-Object -Property Value -Average | select -ExpandProperty Average)}}
The PowerCLI Reference is probably not the best book if you are just starting, it assumes a certain knowledge of PowerShell and a bit of PowerCLI.
There are some quite good introductory books on PowerShell and PowerCLI.
Have a look at these posts for pointers: PowerShell study guide – core concepts and the PowerCLI study guide – core concepts
If you want learn a bit more on handling vSphere statistical data with PowerCLI, you could browse through the series of posts I did on PowerCLI and Statistics.
It explains some of the core concepts, and then builds on that.