Thursday, November 21, 2013

VMware: Switching from CDP to LLDP

Recently my employer changed out our old Catalyst network switches to the new Nexus 2k switches. And it just so happens that the new ones no longer support CDP (Cisco Discovery Protocol).  So we had to change our settings in VMware from CDP to LLDP (Link Layer Discovery Protocol) for our VMware dynamic switches. Not a big deal, just click on the DV switch, go to the advanced properties and change the setting from CDP to LLDP.


Here is where the fun began.
After our network migration we needed to update our documentation for which VMware hosts physical NIC's are plugged into which switch port. I believe the best way to get this info is from power-shell.  So I did some hunting and found a script that was close to what I needed and modified it to my needs. (Thanks IT Walk Thru)

Below is what I came up with.
Now when my network team adds a VLAN, I can tell them which switch ports to apply it too.
Hope this helps someone.

Heath
  1. #create an output array
  2. $MyCollection = @()
  3. Connect-VIServer VitualCenter-ServerName
  4. #Filter out non-connected Hosts
  5. $vmh = Get-VMHost -State "Connected" | sort
  6.   Get-View $vmh | `
  7.   % { $esxname = $_.Name; Get-View $_.ConfigManager.NetworkSystem} | `
  8.   % { foreach ($physnic in $_.NetworkInfo.Pnic) {
  9.     $pnicInfo = $_.QueryNetworkHint($physnic.Device)
  10.     foreach( $hint in $pnicInfo ){
  11.       if ( $hint.LLDPInfo ) {
  12.         $results = New-Object –TypeName PSObject
  13.         $results | Add-Member –MemberType NoteProperty –Name ESXHostName –Value $esxname
  14.         $results | Add-Member –MemberType NoteProperty –Name DeviceName –Value $physnic.Device
  15.         $results | Add-Member –MemberType NoteProperty –Name PortID –Value $hint.LldpInfo.PortId
  16.         $results | Add-Member –MemberType NoteProperty –Name PortName –Value $hint.LldpInfo.Parameter[4].value
  17.         $results | Add-Member –MemberType NoteProperty –Name SwitchName –Value $hint.LldpInfo.Parameter[6].value
  18.                 $MyCollection += $results
  19.         }
  20.        }
  21.     }
  22.   }
  23. $MyCollection | Export-Csv C:\Scripts\vmwarePnic.csv