Link
#Import-Module VMware.VimAutomation.Core
#如果使用 6.5.0 之前版本,需要先导入模块

#Connect-VIServer -Server 192.168.1.1
#连接vCenter

$selectedlocation="Datacenter"
#此处可以设置 Datacenter 名称或者 Cluster 名称以限制范围

$VMHostlist = Get-VMHost -location $selectedlocation


$VMHostHCLInfo = @()
foreach ($VMHost in $VMHostlist){
    $esxcliv2 = Get-EsxCli -VMHost $VMHost -V2
    $viblist = $esxcliv2.software.vib.list.invoke()


#$vmniclist = Get-VMHostNetworkAdapter -Physical -VMHost $VMHost  | Where-Object BitRatePerSec -NE 0 | Sort-Object
    $vmniclist = Get-VMHostNetworkAdapter -Physical -VMHost $VMHost | Sort-Object
    $vmhbalist = Get-VMHostHba -VMHost $VMHost
    $VMHostPciDeviceList = Get-VMHostPciDevice -VMHost $VMHost

    foreach ($vmnic in $vmniclist){
        $info = "" | Select-Object Cluster,VMHost,Name,Driver,Vib,FW,VID,DID,SVID,SSID
        $info.Cluster = Get-VMHost $vmhost | Get-cluster
        $info.VMHost = $vmhost.Name
        $info.Name = $vmnic.Name
        $info.Driver = ($vmnic.ExtensionData.driver).replace("_","-")
        $info.vib = ($viblist | Where-Object Name -Match $info.Driver).id -join ";"
        $argvmnic = $esxcliv2.network.nic.get.CreateArgs()
        $argvmnic.nicname = $vmnic.Name
        $info.FW =  ($esxcliv2.network.nic.get.Invoke($argvmnic)).DriverInfo.FirmwareVersion
        $PCI = $VMHostPciDeviceList | Where-Object Id -EQ $vmnic.ExtensionData.pci
        $info.VID = [STRING]::Format("{0:x}",$PCI.VendorId)
        $info.DID = [STRING]::Format("{0:x}",$PCI.DeviceId)
        $info.SVID = [STRING]::Format("{0:x}",$PCI.SubVendorId)
        $info.SSID = [STRING]::Format("{0:x}",$PCI.SubDeviceId)
        $VMHostHCLInfo += $info
    }

    foreach ($vmhba in $vmhbalist){

        $info = "" | Select-Object Cluster,VMHost,Name,Driver,Vib,FW,VID,DID,SVID,SSID
        $info.Cluster = Get-VMHost $vmhost | Get-cluster
        $info.VMHost = $vmhost.Name
        $info.Name = $vmhba.Name
        $info.Driver = ($vmhba.Driver).replace("_","-")
        # Ignore USB Controller
        if ($info.Driver -like "*usb*" -or $info.Driver  -like "*iLO*" -or $info.Driver -like "*iDRAC*") {
         continue
            }
        $info.vib = ($viblist | Where-Object name -Match $info.Driver | Where-Object name -NotMatch "plugin").id -join ";"
        $saslist = $esxcliv2.storage.san.sas.list.Invoke()
        $fclist = $esxcliv2.storage.san.fc.list.Invoke()
        switch ($vmhba.type){
            "Block"        {$info.FW = ($saslist | Where-Object DeviceName -EQ $vmhba.name).FirmwareVersion}
            "FibreChannel" {$info.FW = ($fclist | Where-Object Adapter -EQ $vmhba.name).FirmwareVersion}
            }
        $PCI = $VMHostPciDeviceList | Where-Object Id -EQ $vmhba.pci
        $info.VID = [STRING]::Format("{0:x}",$PCI.VendorId)
        $info.DID = [STRING]::Format("{0:x}",$PCI.DeviceId)
        $info.SVID = [STRING]::Format("{0:x}",$PCI.SubVendorId)
        $info.SSID = [STRING]::Format("{0:x}",$PCI.SubDeviceId)
        $VMHostHCLInfo += $info
    }

}

$VMHostHCLInfo | ft -AutoSize
$VMHostHCLInfo | Export-Csv -Encoding Default -NoTypeInformation IO-Device-Report-$selectedlocation.csv


# Export to HTML
$css  = "table{ Margin: 0px 0px 0px 4px; Border: 1px solid rgb(200, 200, 200); Font-Family: Tahoma; Font-Size: 8pt; Background-Color: rgb(252, 252, 252); }"
$css += "tr:hover td { Background-Color: #6495ED; Color: rgb(255, 255, 255);}"
$css += "tr:nth-child(even) { Background-Color: rgb(242, 242, 242); }"
Set-Content -Value $css -Path IO-Device-Report-$selectedlocation.css
$VMHostHCLInfo | ConvertTo-Html -CSSUri "IO-Device-Report-$selectedlocation.css" | Set-Content "IO-Device-Report-$selectedlocation.html"