I just ran LucD's script and then sub'd in your modification and the two scripts produce two different results.
Your modification:
PowerCLI C:\> Get-VMhost | Select Name,@{N="Memory used MB";E={$_ | Get-VM | %{$_.MemoryMB} | Measure-Object -Sum | Select -ExpandProperty Sum}}
Name Memory used MB
---- --------------
10.2.5.86 75776
10.2.5.87 106496
10.2.5.85 88064
LucD's script:
PowerCLI C:\> Get-VMhost | Select Name,@{N="Memory used MB";E={ $_ | Get-VM | %{$_.ExtensionData.Summary.QuickStats.HostMemoryUsage} | Measure-Object -Sum | Select -ExpandProperty Sum}}
Name Memory used MB
---- --------------
10.2.5.86 63415
10.2.5.87 87734
10.2.5.85 81205
I ran the two variations back to back. LucD's takes a bit longer to run than yours. When I look at the host's summary page the memory utilization is more consistent with LucD's version. I'm not quite sure why there is a difference or where it is coming from, I just thought I'd throw my two cents in.