Hi LucD, Forum Members,
I'm looking to generate a CSV file of all ESXi hosts in multiple vCenters that have Intel X710 CNAs installed.
The spreadsheet I'm looking to generate is something like:
| vCenter Name | Cluster Name | ESXi HostName | Intel CNA |
| vCenter-01 | Cluster-02 | ESXi-101 | Intel X710 |
| vCenter-01 | Cluster-02 | ESXi-102 | Intel X710 |
| vCenter-02 | Cluster-01 | ESXi-201 | Intel X710 |
| vCenter-02 | Cluster-01 | ESXi-202 | Intel X710 |
The vDocumentation Cmdlets have a great Cmdlet called Get-ESXIODevice that can pull this information, but because it uses ESXCLI to pull this information, the script doesn't scale well.
The information I require is easily accessible via the Vi Client and Web Client under each ESXi host's 'Network Adapters' tab.
Do you know alternative, quicker ways to pull this information?
I found the Cmdlet Get-VMHostPciDevice that is perfect.
The line of code that pulls most of the information I need (except vCenterName and ClusterName) is as follows:
Get-VMHostPciDevice | Where-Object { $_.Name -Like "*X710*" }
Or even shorter again:
Get-VMHostPciDevice -Name "*X710*"
My untested initial draft of code is as follows:
# Create Custom Object
function X710Objects()
{
param ($vCenterName, $ClusterName, $ESXiHostName, $X710Adapter)
$X710Objects = new-object PSObject
$X710Objects | add-member -type NoteProperty -Name vCenterName -Value $vCenterName
$X710Objects | add-member -type NoteProperty -Name ClusterName -Value $ClusterName
$X710Objects | add-member -type NoteProperty -Name ESXiHostName -Value $ESXiHostName
$X710Objects | add-member -type NoteProperty -Name X710Adapter -Value $X710Adapter
Return $X710Objects
}
$vCenterList = Import-CSV -Path .\vCenterList
Foreach ($vC in $vCenterList) {
$ESXiHosts = Get-VMHost | Sort-Object -Property Name
Foreach ($ESXi in $ESXiHosts) {
$PCIDevices = Get-VMHostPciDevice -Name "*X710*"
Foreach ($PCIDev in $PCIDevices) {
$vCenterName = $vC
$clusterName = $ESXi.Parent
$ESXiHostName = $_.VMHost.Name
$X710Adapter = $_.Name
$outputArray += X710Objects $vC $clusterName $ESXiHostName $X710Adapter
} # End PCI Device For Loop
} # End ESXi For Loop
} # End vCenter For Loop
$outputArray | Export-CSV -Path .\outputFile.csv