Leverage Cisco Discovery Protocol w/PowerCLi


If you are a lucky owner of Cisco switches, the Get-VMHostCDP function will give you all the necessary information about the network settings using the Cisco Discovery Protocol.


  • The CDP info for a single network adapter of ESXi host can be retrieved from GUI.


  • The Get-VMHostCDP function from my PowerCLi Vi-Module module retrieves the CDP info for all existing network adapters of any ESXi host(s) and some important ESXi side info. By default, the function returns necessary properties only.
Get-VMHost | Get-VMHostCDP


  • The default behavior can be easy changed by -CdpOnly parameter. Only CDP capable ports will be returned. If no output is returned, probably the CDP is disabled either on the switch or on particular ports.
Get-VMHost | Get-VMHostCDP –CdpOnly


  • To return all or select any properties you want, use the Select-Object cmdlet.
Get-VMHost esx1.* | Get-VMHostCDP -CdpOnly | select *
Get-VMHost esx1.* | Get-VMHostCDP -CdpOnly | select * -exclude mgmt.*
Get-VMHost esx1.* | Get-VMHostCDP -CdpOnly | select NIC, Switch, mgmt*, PortId, Vlan


  • The Get-VMHostCDP function returns custom [ViCDP] object. It has three static methods: ToString(), GetVlan(Id) and GetAllVlan().
Get-VMHost | Get-VMHostCDP | Get-Member


Method ToString()

  • This method gives you brief port-to-port view.
Get-Cluster prod | Get-VMHost | Get-VMHostCDP -CdpOnly | % { $_.ToString() }
  • Just converting the output object to the [string] data type calls the ToString() method in the background and returns the same result.
Get-Cluster prod | Get-VMHost | Get-VMHostCDP -CdpOnly | % { [string]$_ }


Method GetVlan(Id)

  • This method is a VLAN searcher. It allows to find on which port(s) particular VLAN(s) are set. It can search either a single VLAN, several VLANs or any VLAN range.
Get-Cluster prod | Get-VMHost | Get-VMHostCDP -CdpOnly | % { $_.GetVlan(25) } | ft –au
Get-Cluster prod | Get-VMHost | Get-VMHostCDP -CdpOnly | % { $_.GetVlan((23,25)) } | ft –au
Get-Cluster prod | Get-VMHost | Get-VMHostCDP -CdpOnly | % { $_.GetVlan(23..25) } | ft -au


  • Please note when you pass to the method a comma delimited VLAN list, additional parentheses are needed GetVlan((20,30,40)) to recognize a list as a single argument.


Method GetAllVlan()

  • This method gives you vlan-to-port report. It expands the Vlan property from the original object. The GetAllVlan() method especially useful to find port configuration inconsistency within HA/DRS Clusters.
Get-VMHost esx1.* | Get-VMHostCDP -CdpOnly | % { $_.GetAllVlan() } | ft –au
Get-Cluster prod | Get-VMHost | Get-VMHostCDP -CdpOnly | % { $_.GetAllVlan() } | epcsv –notype .\Vlan.csv



The CISCO side

  • Despite the CDP is enabled by default on the Cisco devices, may happen it was disabled for any reason on your switch. For completeness I decided to write a short briefing how to enable the CDP back.

  • Connect to the switch, enter to Enable mode to view global CDP status. Why global? The reason is the CDP have to be enabled on two levels: globally on the device level and per port.

sh cdp
  • Enter to the Global Configuration mode and enable CDP on the switch.
conf t
cdp run
  • Review CDP status on particular port or on all switch ports.
do sh cdp int e0/1
do sh cdp int
  • Enter to Interface Configuration mode by selecting either a single port, port range where your ESXI hosts are connected or all switch ports and enable the CDP on these ports.
int f0/1
int range g0/1-10, e1/1-4
int range g0/1-24
cdp ena
  • To persist the changes you made, copy running to startup configuration.
do copy run start


  • All done. Now there is no reason to get an empty output while using -CdpOnly parameter.


  • The CDP is a great enhancement that helps to VMware administrators to troubleshot network issues especially in enterprises where Networking and System teams are separated.
  • For more details about the function, please take a look at the content based help and examples.

Get-Alias –Definition Get-VMHostCDP
Get-Help Get-VMHostCDP -Full
Get-Help Get-VMHostCDP -Examples
Get-Help Get-VMHostCDP -Parameter CdpOnly

You might also like

Get-VMHostFirmwareVersion – Get ESXi servers BIOS/Firmware version
Compare-VMHost – Compare two or more ESXi hosts
Get-ViSession/Disconnect-ViSession – List and disconnect VCenter sessions
Search-Datastore – Browse/Search VMware Datastores

10 thoughts on “Leverage Cisco Discovery Protocol w/PowerCLi

      1. You can use calculated property:

        Get-VMHost | Get-VMHostCDP -CdpOnly | select *, @{N='Parent'; E={(Get-VMHost "$($_.VMHost).*").Parent.Name}}


  1. Do you also have the problem, that not all VLAN (which are on the Port configured) are listed in the result? How could i fix this?


      1. Do you have Powered on VM, connected to appropriate PortGroups, configured for those VLAN ? If no, try to vMotion any VM to the hosts that do not see some VLAN. I had this problem too for non VMkernel VLANs…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s