Search This Blog

Wednesday, January 18, 2012

a VERY LONG onliner to get Cisco CDP from a VMware dvSwitch (or vSwitch)

Here's a VERY LONG onliner to get Cisco CDP (Cisco Discovery Protocol) info of vmnics (Ethernet adapters) connected to physical or virtual switches. In this case, the vmnics are physical. So this script GETS physical switch output. See example below:

This Oneliner is broken into mutiple lines for ease of use. But it can be condensed to ONE LINE. Yehaw!
Get-view -ViewType HostSystem -Filter @{"Name"="$VMhost"} -Property ConfigManager.NetworkSystem, Name | sort name | % { $n=$_.name ; $objConfigManager_NetworkSystem = get-view $_.ConfigManager.NetworkSystem ; $objConfigManager_NetworkSystem | % { $_.NetworkInfo } | % { $_.Pnic } | SELECT @{N="Name"; E={$n} } , device, pci, mac, @{N="PortID" ; E= { $objConfigManager_NetworkSystem.QueryNetworkHint($_.Device) | % { $_.ConnectedSwitchPort.PortID } } }, @{N="DevID" ; E= { $objConfigManager_NetworkSystem.QueryNetworkHint($_.Device) | % { $_.ConnectedSwitchPort.DevID } } } | ? { $_.Device -match "vmnic" }
}

Output Example:
NameDevicePCIMACPortIDDeviceID
esxhstesx01.us.ano.netvmnic001:00.000:34:84:5d:75:a4GigabitEthernet2/0/9C3750x.phx.az.anon.com
esxhstesx01.us.ano.netvmnic101:00.100:23:44:5d:75:a6GigabitEthernet1/0/11C3750x.phx.az.anon.com
esxhstesx01.us.ano.netvmnic204:00.000:43:33:90:77:78GigabitEthernet2/0/11C3750x.phx.az.anon.com
esxhstesx01.us.ano.netvmnic304:00.100:77:33:90:77:79GigabitEthernet1/0/9C3750x.phx.az.anon.com

No comments:

Post a Comment