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

#Connect-VIServer -Server 192.168.1.1
#连接vCenter


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

$VMHostlist = Get-VMHost -location $selectedlocation | Sort-Object
$AllInfo = @()

foreach ($VMHost in $VMHostlist){

$Mgmtvmk=Get-VMHostNetworkAdapter -VMHost $VMHost -VMKernel | where {$_.ManagementTrafficEnabled -eq $True }
$MgmtvmkVLAN=Get-VirtualPortGroup -VMHost $VMHost -Name $Mgmtvmk.PortGroupName 

$vMotionvmk=Get-VMHostNetworkAdapter -VMHost $VMHost -VMKernel | where {$_.vMotionEnabled -eq $True }
$vMotionvmkVLAN=Get-VirtualPortGroup -VMHost $VMHost -Name $vMotionvmk.PortGroupName 

$vSANvmk=Get-VMHostNetworkAdapter -VMHost $VMHost -VMKernel | where {$_.VsanTrafficEnabled -eq $True }
$vSANvmkVLAN=Get-VirtualPortGroup -VMHost $VMHost -Name $vSANvmk.PortGroupName 

$Info = "" | Select VMHost,MGMT_vmk,MGMT_VLAN, MGMT_IP,vMotion_vmk,vMotion_VLAN, vMotion_IP,vSAN_vmk,vSAN_VLAN, vSAN_IP
      $Info.VMHost = $vmHost.Name
      $Info.MGMT_vmk = $Mgmtvmk.Name
      $Info.MGMT_VLAN = $MgmtvmkVLAN.VlanId
      $Info.MGMT_IP = $Mgmtvmk.ip
      
      $Info.vMotion_vmk = $vMotionvmk.Name
      $Info.vMotion_VLAN = $vMotionvmkVLAN.VlanId
      $Info.vMotion_IP = $vMotionvmk.ip
      
      $Info.vSAN_vmk = $vSANvmk.Name
      $Info.vSAN_VLAN = $vSANvmkVLAN.VlanId
      $Info.vSAN_IP = $vSANvmk.ip
      
      $AllInfo += $Info
}

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