VMware ESXi CDP information via PowerCLI
- Using PowerCLI, connect to the ESX host or vCenter Server:# Connect-VIServer esx-or-vc-hostname
- Run this script in PowerCLI:
Get-VMHost | Where-Object {$_.ConnectionState -eq "Connected"} | %{Get-View $_.ID} | %{$esxname = $_.Name; Get-View $_.ConfigManager.NetworkSystem} | %{ foreach($physnic in $_.NetworkInfo.Pnic){ $pnicInfo = $_.QueryNetworkHint($physnic.Device) foreach($hint in $pnicInfo){ Write-Host $esxname $physnic.Device if( $hint.ConnectedSwitchPort ) { $hint.ConnectedSwitchPort } else { Write-Host "No CDP information available."; Write-Host } } } }