Collect ESXI NIC Information

      1 Comment on Collect ESXI NIC Information

Keeping a stable environment is a key part of any business and in virtualization drivers/firmware matter quite a bit!
This is a very handy script that will iterate through a whole VCenter or collection of VCenter servers and get all hosts NIC cards driver/firmware information.

The script was originally created by another blogger, I’ve added a few quick modifications however all credit should go to Kyle Ruddy who wrote the code originally.

My changes:
Originally it was meant to work cluster by cluster, now it will get all hosts in all connected VCenter servers.
Added optional CSV output. If you specify a CSV file it will write to it, alternatively it will just output to the screen.

Usage:
.\getNicInfo.ps1 output.csv
(Assuming you are already connected to one or more vcenter servers)
Again, output.csv is optional, please omit it if you just want to display to your screen.

#
#Original code by: Kyle Ruddy
#Name: getNicInfo.ps1 
#Date: 10/30/2014
#Modified by: Me
#Date: 10/08/2016
#
PARAM (
   [Parameter(HelpMessage="CSV filename to be created.", Mandatory=$false)][string] $CSVFile
)

#Setting global variables
$output = @()

#Gather available VMHosts
$vmhosts = Get-VMHost | where {$_.State -eq 'Maintenance' -or $_.State -eq 'Connected'} | sort Name

#Loop through each VMHost gathering information
foreach ($vmh in $vmhosts) {
#Null variables which will be reused in the loop
$esxcli = $niclist = $null

#Connect to the vmhost via esxcli and then pull its NICs
$esxcli = $vmh | Get-EsxCli
$niclist = $esxcli.network.nic.list()

#Loop through each NIC gathering information
foreach ($nic in $niclist) {
#Null variables which will be reused in the loop
$tempvar = $driverinfo = $null

#Gather NIC information from the DriverInfo selection
$driverinfo = $esxcli.network.nic.get($nic.Name).DriverInfo

#Feed NIC information into a variable to be displayed later
$tempvar = "" | select VMHost,Nic,Driver,DV,FV
$tempvar.VMHost = ($vmh.Name).Split('.')[0]
$tempvar.Nic = $nic.Name
$tempvar.Driver = $driverinfo.Driver
$tempvar.DV = $driverinfo.Version
$tempvar.FV = $driverinfo.FirmwareVersion

#Add the above variable to variable that's to be the final result
$output += $tempvar
}}
if ($CSVFile) {
	#Write to CSV if parameter was specified
	$output | select VMHost,NIC,Driver,@{Name='Driver Version';Expression={$_.DV}},@{Name='Firmware Version';Expression={$_.FV}} |Export-Csv .\$CSVFile -NoTypeInformation
} else {
	# otherwise write to screen
	$output | select VMHost,NIC,Driver,@{Name='Driver Version';Expression={$_.DV}},@{Name='Firmware Version';Expression={$_.FV}} |Format-Table
}

File: getNicInfo

1 thought on “Collect ESXI NIC Information

Leave a Reply

Your email address will not be published. Required fields are marked *