4 minute read

Sometimes we need to quickly grab some of the IDs from ESXi hardware components to compare them with the right item in the VMware HCLs.

In my specific case, I needed to get the IDs to check the Network drivers and firmware versions:

VMware HCL IO Compabitility List

But the quick script has the option to collect more than just the Network cards, by updating the list named deviceClassNamesList:

$deviceClassNamesList = @("Ethernet")

If you want to collect info for some other type of devices you just need to add the string that you are looking from the field/property DeviceClassName, for example list also for SATA controllers:

$deviceClassNamesList = @("Ethernet", "SATA")

Script input file

To make my life easier we use a CSV file as the input, to allow the collection of info across multiple vCenters and multiple vSphere clusters.

vcenter cluster
xyz.local cluster01
abc.local cluster00
xyz.local cluster02

Input file that would match the above table will be:

vcenter,cluster
xyz.local,cluster01
abc.local,cluster00
xyz.local,cluster02

There are some optimisations in the script to try to re-use the same vCente connection as much as possible. That will affect the output since info could be in a different order compared to the input file order. The assumption is that the user account used to login in the vCenter is the same across all the vCenters in the list, but is not much of a stretch to adapt the script to start asking credentials for each new connection, would be just the matter of moving the get credentials section to right before the new vCenter connection.

Some editable parameters on the script

At the top of the script there are a couple of variables that can be edited to:

  • manage the input/output filenames
  • some formatting options, because of some differences of how MacOS and Microsoft Windows handle the CSV files
  • DeviceClassNames to retrieve info for
$csvInputFilename = "cluster_list.csv"
$csvOutputFilename = "esxi_nics_pci-info.csv"
$csvDelimiter = ","

$deviceClassNamesList = @("Ethernet")

The information that we are trying to collect

The info that we want to collect is the info that we can collect by login in to an ESXi Host and run:

  • lspci -v
    lspci output
  • esxcli hardware pci list
    esxcli hardware pci list output

The script

$csvInputFilename = "cluster_list.csv"
$csvOutputFilename = "esxi_nics_pci-info.csv"

$csvDelimiter = ","

$deviceClassNamesList = @("Ethernet")

# Edit at your own risk from this point ;)

#Add Credentials
Write-Host "-> vCenter Credentials: $vcenter" -ForegroundColor Red
$credentials = Get-Credential

# Import CSV
if ($csvDelimiter -eq "") {
    $csvDelimiter = ","
}
Write-Host "> Import CSV Delimiter: $($csvDelimiter)" -ForegroundColor DarkGreen
Write-Host "> Input CSV File: $($csvInputFilename)" -ForegroundColor DarkGreen
Write-Host "> Output CSV File: $($csvOutputFilename)" -ForegroundColor DarkGreen
Write-Host "> DeviceClassNamesList: $($deviceClassNamesList)`n" -ForegroundColor DarkGreen

$esxiToCollectInfo = Import-CSV -Delimiter "$($csvDelimiter)" $csvInputFilename | Sort-Object { $_.vcenter }

$currentVCenter = $null
$vcenterSession = $null
$dataReport = @()

foreach($object in $esxiToCollectInfo) {
    if($object.vcenter -ne $currentvCenter) {
        if($currentVCenter) {
            Write-Host "---> Disconnect vCenter: $($currentVCenter) - Disconnect before Connect to vCenter: $($object.vcenter)" -ForegroundColor Magenta
            Disconnect-VIServer $vcenterSession -Confirm
        }
        $currentVCenter = $object.vcenter
        Write-Host "--> Connect vCenter: $($currentVCenter)" -ForegroundColor Cyan
        $vcenterSession = Connect-VIServer -Server $currentVCenter -Credential $credentials
    }

    Write-Host "---> Get Hosts from cluster: $($object.cluster)" -ForegroundColor DarkCyan
    $esxiHosts = Get-Cluster $object.cluster | Get-VMHost

    foreach ($esxi in $esxiHosts) {
        Write-Host "----> Get info from host: $($esxi.Name)" -ForegroundColor Green
        $esxcli = Get-EsxCli -VMHost $esxi -V2
        $pciNicInfo = $esxcli.hardware.pci.list.Invoke()| Where-Object { $_.DeviceClassName | Select-String -Pattern $deviceClassNamesList }
        foreach ($nicInfo in $pciNicInfo) {
            # Prepare object for CSV
            $reportObj = [PSCustomObject]@{
                VCenter             = $currentVCenter
                Cluster             = $object.cluster
                HostName            = $esxi.Name
                DeviceName          = $nicInfo.DeviceName
                DeviceClassName     = $nicInfo.DeviceClassName
                ModuleName          = $nicInfo.ModuleName
                NUMANode            = $nicInfo.NUMANode
                VendorName          = $nicInfo.VendorName
                VendorID            = [System.Convert]::ToString($nicInfo.VendorID,16)
                DeviceID            = [System.Convert]::ToString($nicInfo.DeviceID,16)
                SubVendorID         = [System.Convert]::ToString($nicInfo.SubVendorID,16)
                SubDeviceID         = [System.Convert]::ToString($nicInfo.SubDeviceID,16)
            }
            # Add the object to the report array
            $dataReport += $reportObj
        }
    }
    $dataReport | Export-Csv -Path $csvOutputFilename -NoTypeInformation -UseCulture 
}

if($currentVCenter) {
    Write-Host "--> Disconnect vCenter: $($currentVCenter) - END" -ForegroundColor Magenta
    Disconnect-VIServer $vcenterSession -Confirm
} else {
    Write-Host "-> Disconnect from all vCenters" -ForegroundColor Red
    Disconnect-VIServer * -Confirm
}

Output

  • Script run
    script run
  • Output File Result
    "VCenter","Cluster","HostName","DeviceName","DeviceClassName","ModuleName","NUMANode","VendorName","VendorID","DeviceID","SubVendorID","SubDeviceID"
    "vcenter.xxxx","Main Cluster","esx01.xxxx","Xeon E7 v4/Xeon E5 v4/Xeon E3 v4/Xeon D Crystal Beach DMA Channel 7","System peripheral","None","0","Intel Corporation","32902","28455","5593","2100"
    "vcenter.xxxx","Main Cluster","esx01.xxxx","I350 Gigabit Network Connection","Ethernet controller","igbn","0","Intel Corporation","32902","5409","5593","5409"