# This script will get the ESXi hostname, MAC address and vmnic of all physical NICs
# It will loop through all the hosts in the specified cluster and output the results to a CSV file
# Connect to the vCenter server
Connect-VIServer -Server <vcenterserver> -Credential (Get-Credential)
# Specify the cluster name
$cluster = "DCA-Cluster01"
# Get all the hosts in the cluster
$esxihosts = Get-Cluster -Name $cluster | Get-VMHost
# Create an empty array to store the results
$results = @()
# Loop through each host
foreach ($esxihost in $esxihosts) {
# Get the hostname
$esxihostname = $esxihost.Name
# Get all the physical NICs
$pNICs = Get-VMHostNetworkAdapter -VMHost $esxihost -Physical
# Loop through each physical NIC
foreach ($pNIC in $pNICs) {
# Get the MAC address and vmnic name
$mac = $pNIC.Mac
$vmnic = $pNIC.Name
# Create a custom object with the properties
$result = [PSCustomObject]@{
Hostname = $esxihostname
MAC = $mac
vmnic = $vmnic
}
# Add the object to the array
$results += $result
}
}
# Export the array to a CSV file
$results | Export-Csv -Path C:\temp\pNICs.csv -NoTypeInformation
# Disconnect from the vCenter server
# Disconnect-VIServer -Server <vcenterserver> -Confirm:$false
Output from:
"Hostname","MAC","vmnic"
"srv-esx11.mmt.local","b0:7b:26:de:6d:cc","vmnic0"
"srv-esx11.mmt.local","b0:7b:27:de:8d:cd","vmnic1"
"srv-esx11.mmt.local","bc:97:e8:f3:3f:40","vmnic2"
"srv-esx11.mmt.local","bc:97:e5:f3:4f:41","vmnic3"