I use something like the following to get the dropped packets per VM for all the ESXi hosts.
It allows the definition of a start and finish time.
Note that the vNICs will be displayed as the interval deviceID of these vNICs on the VM.
You could fetch the VM and translate the deviceID into the label like "Network Adapter 1", but that would only work if the VM still exists and if the vNIC configuration hasn't changed in between.
$start = Get-Date "22/09/14 11:30"
$finish = Get-Date "22/09/14 17:30"
$metrics = "net.droppedRx.summation","net.droppedTx.summation"
foreach($esx in (Get-VMHost)){
$vms = Get-VM -Location $esx
if($vms){
Get-Stat -Entity $vms -Stat $metrics -Start $start -Finish $finish -ErrorAction SilentlyContinue |
where {$_.Instance -ne ""} |
Group-Object -Property {$_.Entity.Name,$_.Instance} | %{
$_.Group | Group-Object -Property Timestamp | %{
New-Object PSObject -Property @{
VMHost = $esx.Name
VM = $_.Group[0].Entity.Name
VmNic = $_.Group[0].Instance
"Receive Dropped Packets" = $_.Group | where {$_.MetricId -eq "net.droppedRx.summation"} |
Select -ExpandProperty Value
"Transmit Dropped Packets" = $_.Group | where {$_.MetricId -eq "net.droppedTx.summation"} |
Select -ExpandProperty Value
Timestamp = $_.Group[0].Timestamp
"Interval (seconds)" = $_.Group[0].IntervalSecs
}
}
}
}
}