Mallik7
Enthusiast
Enthusiast

Looking for a PowerCLI script to get the ESXi hosts all the NIC driver and firmware version

Jump to solution

Looking for a PowerCLI script to get the output of ESXi hosts all the NIC driver and firmware version (ESXi OS 6.0 and 6.5). Script should have ability to capture the host names from a input file and save the output in .csv format with date in file name.

Thanks in advance.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try something like this

# Input in CSV file

#

# VMHostName

# esx1

# esx2

#

$esxNames = Import-Csv -Path .\hostnames.csv -UseCulture |

            select -ExpandProperty VMHostName

Get-VMHost -Name $esxNames -PipelineVariable esx |

ForEach-Object -Process {

    $esxcli = Get-EsxCli -VMHost $_ -V2

    $esxcli.network.nic.list.Invoke() |

    where{$_.Name -match "^vmnic"} |

    ForEach-Object -Process {

        $nic = $_

        $esxcli.network.nic.get.Invoke(@{nicname=$_.Name}).DriverInfo |

        ForEach-Object -Process {

            [PSCustomObject]@{

                VMHost = $esx.Name

                Nic = $nic.Name

                Driver = $_.Driver

                Version = $_.Version

                Firmware = $_.FirmwareVersion       

            }

        }

    }

} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

7 Replies
LucD
Leadership
Leadership

Try something like this

# Input in CSV file

#

# VMHostName

# esx1

# esx2

#

$esxNames = Import-Csv -Path .\hostnames.csv -UseCulture |

            select -ExpandProperty VMHostName

Get-VMHost -Name $esxNames -PipelineVariable esx |

ForEach-Object -Process {

    $esxcli = Get-EsxCli -VMHost $_ -V2

    $esxcli.network.nic.list.Invoke() |

    where{$_.Name -match "^vmnic"} |

    ForEach-Object -Process {

        $nic = $_

        $esxcli.network.nic.get.Invoke(@{nicname=$_.Name}).DriverInfo |

        ForEach-Object -Process {

            [PSCustomObject]@{

                VMHost = $esx.Name

                Nic = $nic.Name

                Driver = $_.Driver

                Version = $_.Version

                Firmware = $_.FirmwareVersion       

            }

        }

    }

} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Mallik7
Enthusiast
Enthusiast

it is throwing an error here -

Get-VMHost -Name $esxNames -PipelineVariable esx |

Get-VMHost : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is

not null or empty, and then try the command again.

At C:\MVstuff\Network-DriverFW-Check\Network-Driver-FW-version-Check.ps1:4 <file:///C:\MVstuff\Network-DriverFW-Check\Network-Driver-FW-version-Check.ps1:4>  char:18

+ Get-VMHost -Name $esxNames -PipelineVariable esx |

+                  ~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Get-VMHost], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost  

0 Kudos
LucD
Leadership
Leadership

What did you put in the input CSV file?
Did you follow the layout I gave in the comments at the start of the snippet?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Narayanan_5245
Enthusiast
Enthusiast

Hi LuCD,

Can we able to give the input to fetch the host details from the vCenter server? Please help to suggest

thank you

Regards

Narayanan.

0 Kudos
AlbertWT
Virtuoso
Virtuoso

narayan​,

change the below lines:

Get-VMHost -Name $esxNames -PipelineVariable esx |

into:

Get-VMHost -PipelineVariable esx |

/* Any kind of comment or input would be greatly appreciated */
0 Kudos
Raghukalloor
Contributor
Contributor

Hi Lucd,

How can we add description of the nic which shows us the model name of the nics

 

0 Kudos
LucD
Leadership
Leadership

Try something like this

 

$esxNames = Import-Csv -Path .\hostnames.csv -UseCulture |
            select -ExpandProperty VMHostName
Get-VMHost -Name $esxNames -PipelineVariable esx |
ForEach-Object -Process {
    $esxcli = Get-EsxCli -VMHost $_ -V2
    $esxcli.network.nic.list.Invoke() |
    where{$_.Name -match "^vmnic"|
    ForEach-Object -Process {
        $nic = $_
        $esxcli.network.nic.get.Invoke(@{nicname=$_.Name}).DriverInfo |
        ForEach-Object -Process {
            [PSCustomObject]@{
                VMHost = $esx.Name
                Nic = $nic.Name
                Description = $nic.Description
                Driver = $_.Driver
                Version = $_.Version
                Firmware = $_.FirmwareVersion       
            }
        }
    }
| Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos