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 | Sort-Object

$AllInfo = @()

foreach ($VMHost in $VMHostlist){

$hosthardwareinfo= Get-vmhost $VMHost | Get-VMhostHardware
$mgmtip=Get-VMHostNetworkAdapter -VMHost $VMHost -VMKernel | where {$_.ManagementTrafficEnabled -eq $True }

$Info = "" | Select Cluster, VMHost, MGMT_IP, Build, Manufacturer, Model, BIOS, SN, CPU, CpuNum, CpuCores, Mem
      $info.Cluster=  Get-VMHost $vmHost | Get-cluster
      $Info.VMHost = $vmHost.Name
      $Info.MGMT_IP = $mgmtip.ip
      $Info.Build = $vmHost.Build
      $Info.Manufacturer = $hosthardwareinfo.Manufacturer
      $Info.Model = $hosthardwareinfo.Model
      $Info.BIOS=  $hosthardwareinfo.BiosVersion
      $Info.SN=  $hosthardwareinfo.SerialNumber     
      $Info.CPU = $hosthardwareinfo.CpuModel
      $Info.CpuNum = $hosthardwareinfo.CpuCount
      $Info.CpuCores = $hosthardwareinfo.CpuCoreCountTotal
      $Info.Mem = $VMHost.MemoryTotalGB

      $AllInfo += $Info
}

$AllInfo |Export-Csv -NoTypeInformation Hardwareinfo-of-$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 Hardwareinfo-of-$selectedlocation.css
$AllInfo | ConvertTo-Html -CSSUri "Hardwareinfo-of-$selectedlocation.css" | Set-Content "Hardwareinfo-of-$selectedlocation.html"