Get vSphere network info using PowerCLI & CDP

PowerCLI is powerfull stuff. It can be used to set specific configuration for your vSphere environment, but it can also be used to collect information. This post will go into detail how to get network information using VMware PowerCLI and Cisco Discovery Protocol (CDP).

Cisco Discovery Protocol (CDP)

CDP is used to share information about other directly-connected Cisco networking equipment, such as upstream physical switches. CDP allows ESX and ESXi administrators to determine which Cisco switch port is connected to a given vSwitch. When CDP is enabled for a particular vSwitch, properties of the Cisco switch, such as device ID, software version, and timeout, may be viewed from the vSphere Client. This information is useful when troubleshooting network connectivity issues related to VLAN tagging methods on virtual and physical port settings.

CDP under VMware vSphere

By default ESX(i) has the CDP protocol on the vSwitch configured to the mode Listen. This enables you to view all relevant information with regards to your Cisco network.

To show this information under the vSphere client you have to enable CDP on the ESX(i) host and the Cisco switch. This KB article by VMware is a good reference on how to enable CDP. You can also view the configuration guide of ESX or ESXi.

If all works fine you can view the network information by clicking the info icon next to the vSwitch :

For more information on CDP under vSphere see this KB article.

PowerCLI & CDP

When CDP is enabled you can use PowerCLI to generate network information output for your vSphere environment. This is very usefull information which you can use for troubleshooting or in my case to prepare for a migration.

The KB article by VMware already gives a good PowerCLI script to get network information of all the connected NICs on a specific ESX(i) host.

Get-VMHost | Where-Object {$_.State -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 ) {
} else {
Write-Host “No CDP information available.”; Write-Host } } } }

If your not a scriptkiddie, you can also use PowerGUI and import the VMware Community PowerPack to do the work for you. This will, when you are connected to a vCenter host, provide you with a list of all the NICs in your ESX(i) hosts and their network information.

Relevant links

More information on CDP & ESXi: – Configure Cisco CDP on ESX(i)