Try something like this
$VmInfo=ForEach ($Datacenterin (Get-Datacenter|Sort-Object-PropertyName)) {
ForEach ($Clusterin ($Datacenter|Get-Cluster|Sort-Object-PropertyName)) {
$vms=Get-Cluster-Name$Cluster|Get-VM
foreach($vmStatin (Get-Stat-Entity$vms-Start (Get-Date).AddMonths(-1) -Stat"mem.usage.average"|
Group-Object-Property {$_.Entity.Name})){
$memAvgGB=$vmStat.Group[0].Entity.MemoryGB* ($vmStat.Group|Measure-Object-PropertyValue-Average|Select-ExpandPropertyAverage) /100
ForEach ($HardDiskin (Get-HardDisk-VM$vmStat.Values[0] |Sort-Object-PropertyName)) {
""|Select-Object-Property@{N="VM-name";E={$vmStat.Values[0]}},
@{N="CPU";E={$vmStat.Group[0].Entity.NumCpu}},
@{N="Uptime (Days)";E={(New-TimeSpan$vmStat.Group[0].Entity.ExtensionData.Summary.Runtime.BootTime (Get-Date)).days}},
@{N="Memory Total (GB)";E={$vmStat.Group[0].Entity.MemoryGB}},
@{N="Memory Avg (GB)";E={[Math]::Round($memAvgGB,3)}},
@{N="HDD";E={$HardDisk.Name}},
@{N="HDD Capacity (GB)";E={$HardDisk.CapacityGB}},
@{N="HDD Datastore";E={$HardDisk.FileName.Split("]")[1].Trim('')}}
}
}
}
}
$VmInfo