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.
Get-VMHostCDP
- 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)
andGetAllVlan()
.
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 theToString()
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. TheGetAllVlan()
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.
ena 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.
Summary
- 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
great tool, is there a way to get the VMHost Parent in the Output?
LikeLike
Do you mean a cluster name?
LikeLike
yes
LikeLike
You can use calculated property:
LikeLike
thx, that’s working
LikeLike
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?
LikeLike
Do you see those VLAN in the Web Client on all hosts in the cluster ?
LikeLike
just checked, no the can’t be seen in the Web Client either – strange
LikeLike
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…
LikeLike