Try it like this
$esx=Get-VMHost
$stat="net.received.average","net.transmitted.average"
$start= (Get-Date).AddMinutes(-30)
Get-Stat-Entity$esx-Stat$stat-Start$start-Realtime|
Group-Object-Property {$_.Entity.Name} |%{
$record=New-ObjectPSObject-Property@{
CollectionTime=$_.Group[0].Timestamp
Host= $_.Name
}
$_.Group|where {$_.Instance-match"vmnic"} |
Group-Object-PropertyInstance|%{
$RxValue=$_.group|where {$_.MetricId-eq"net.received.average"} |
Measure-Object-PropertyValue-Average-Maximum
$TxValue=$_.group|where {$_.MetricId-eq"net.transmitted.average"} |
Measure-Object-PropertyValue-Average-Maximum
Add-Member-InputObject$record-Name ($_.Name+"AvgRx (KBps)") -Value ([math]::Round($RxValue.Average,1)) -MemberTypeNoteProperty
Add-Member-InputObject$record-Name ($_.Name+"AvgTx (KBps)") -Value ([math]::Round($TxValue.Average,1)) -MemberTypeNoteProperty
Add-Member-InputObject$record-Name ($_.Name+"MaxRx (KBps)") -Value ([math]::Round($RxValue.Maximum,1)) -MemberTypeNoteProperty
Add-Member-InputObject$record-Name ($_.Name+"MaxTx (KBps)") -Value ([math]::Round($RxValue.Maximum,1)) -MemberTypeNoteProperty
}
$record
}