How to extract physical NIC (pNIC) statistics for ESXi hosts in a vCenter cluster using PowerCLI
search cancel

How to extract physical NIC (pNIC) statistics for ESXi hosts in a vCenter cluster using PowerCLI

book

Article ID: 426557

calendar_today

Updated On:

Products

VMware vSphere ESXi VMware vCenter Server

Issue/Introduction

Administrators may need to perform a deep-dive audit of physical network interface (pNIC) statistics across multiple ESXi hosts to troubleshoot packet loss, CRC errors, or performance degradation. Standard vCenter performance charts may not provide the granular hardware-level error counters (e.g., FIFO errors, Heartbeat errors) required for root cause analysis.

Environment

7.x, 8.x, 9.x

Cause

Diagnostic requirement for low-level NIC statistics (Receive/Transmit drops and errors) across a specific cluster.

 

Resolution

Prerequisites:

  1. PowerCLI installed and authenticated to the vCenter Server.
  2. Execution policy set to allow script execution.

Script:

Connect-VIServer -Server <VCENTER_FQDN_OR_IP>

# 1. Define the Cluster target
$clusterName = Read-Host "Enter the name of the Cluster you want to audit"
$cluster = Get-Cluster -Name $clusterName -ErrorAction SilentlyContinue

if (-not $cluster) {
    Write-Host "Could not find a cluster named '$clusterName'." -ForegroundColor Red
    return
}

# 2. Retrieve connected hosts
$esxiHosts = Get-VMHost -Location $cluster | Where-Object { $_.ConnectionState -eq "Connected" }

Write-Host "`nAuditing Cluster: $($cluster.Name) ($($esxiHosts.Count) Hosts Found)" -ForegroundColor Green

foreach ($vmhost in $esxiHosts) {
    Write-Host "`n" + ("=" * 60)
    Write-Host " HOST: $($vmhost.Name)" -ForegroundColor Cyan
    Write-Host ("=" * 60)
    
    try {
        $esxcli = Get-EsxCli -VMHost $vmhost -V2
        $pnics = $vmhost.ExtensionData.Config.Network.Pnic
        
        foreach ($pnic in $pnics) {
            $nicName = $pnic.Device
            $s = $esxcli.network.nic.stats.get.Invoke(@{nicname = $nicName})

            Write-Host "`n [ NIC: $nicName ]" -ForegroundColor Yellow
            
            $output = @"
   Packets received: $($s.PacketsReceived)
   Packets sent: $($s.PacketsTransmitted)
   Bytes received: $($s.BytesReceived)
   Bytes sent: $($s.BytesTransmitted)
   Receive packets dropped: $($s.ReceivePacketsDropped)
   Transmit packets dropped: $($s.TransmitPacketsDropped)
   Multicast packets received: $($s.MulticastPacketsReceived)
   Broadcast packets received: $($s.BroadcastPacketsReceived)
   Multicast packets sent: $($s.MulticastPacketsTransmitted)
   Broadcast packets sent: $($s.BroadcastPacketsTransmitted)
   Total receive errors: $($s.ReceiveErrors)
   Receive length errors: $($s.ReceiveLengthErrors)
   Receive over errors: $($s.ReceiveOverErrors)
   Receive CRC errors: $($s.ReceiveCRCErrors)
   Receive frame errors: $($s.ReceiveFrameErrors)
   Receive FIFO errors: $($s.ReceiveFIFOErrors)
   Receive missed errors: $($s.ReceiveMissedErrors)
   Total transmit errors: $($s.TransmitErrors)
   Transmit aborted errors: $($s.TransmitAbortedErrors)
   Transmit carrier errors: $($s.TransmitCarrierErrors)
   Transmit FIFO errors: $($s.TransmitFIFOErrors)
   Transmit heartbeat errors: $($s.TransmitHeartbeatErrors)
   Transmit window errors: $($s.TransmitWindowErrors)
"@
            Write-Host $output
        }
    }
    catch {
        Write-Host " [!] Error accessing host $($vmhost.Name): $($_.Exception.Message)" -ForegroundColor Red
    }
}




Additional Information

For trend analysis, run this script daily and compare ReceiveCRCErrors or ReceivePacketsDropped. Frequent increments in these counters typically indicate physical layer issues (cabling, SFP, or switch port configuration).