Since ESX 3.5 now has CDP implemented, how can we get the physical switch name and the switch port, like it is in VC 2.5 showed?
Only via the SDK I'm afraid.
The CDP information is returned in the PhysicalNicCdpInfo object.
This object can be retrieved with the QueryNetworkHint method.
Something like this should give you the CDP information for each pNIC on each ESX server under the VC.
Get-VMHost | %{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 $hint.connectedSwitchPort } } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If you enable CDP on the vSwitches on your ESX 3.5.x systems, you can actually get this info via the commandline using "esxcfg-info | grep cdp", this information is listed in the network section contained in XML like tags, but you'll get all the info you see on the Virtual Center GUI. As in the previous post, you can retrieve this info via the toolkit, but if you want to manage one less component you can still get it through the traditional esx commands.
I tried that script. Instead of the cdp info I am getting this... VMware.Vim.PhysicalNicCdpInfo on all of my nics that are cdp enabled. Any thoughts?
Thanks,
Jason
I figured it out. I changed the write-host line to write-output and then it showed me the cdp info.
Thanks,
Jason
From ESX server
esxcfg-info | grep -C 18 "\==+CDP Summary"
I am not able to get this to work. When i execute the code, I receive this error. Any ideas?
Unexpected token 'foreach' in expression or statement.
At line:1 char:200
+ Get-VMHost | %{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 $hint.connectedSwitchPort } } }
It seems you lost the newlines when copying the script code.
Afaik this only seems to work correctly with FF.
See also (and many other posts)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That was the problem. Thanks! I was able to save the webpage from IE7 and open it in Word 2007 and it did reflect the correct formatting.
Hi all
How can I export specifi fields to CSV file ? I would like to have an report with similar layout:
Hostname | vmnic | DeviceID | PortID
Thanks in advance
Artur
Hi Artur,
I did a little rewrite of Luc's script to present the requested information in a .csv file:
Get-VMHost | Get-View | ForEach-Object { $VMHost = $_ Get-View $VMHost.ConfigManager.NetworkSystem } | ForEach-Object { foreach ($physnic in $_.NetworkInfo.Pnic) { $pnicInfo = $_.QueryNetworkHint($physnic.Device) foreach($hint in $pnicInfo){ $Report = "" | Select-Object -Property VMHost,vmnic,DeviceId,PortId $Report.VMHost = $VMHost.Name $Report.vmnic = $physnic.Device $Report.DeviceId = $hint.connectedSwitchPort.DevId $Report.PortId = $hint.connectedSwitchPort.PortId $Report } } } | Sort-Object -Property VMHost,vmnic | ` Export-Csv -Path VMHostSwitchPorts.csv -NoTypeInformation -UseCulture
Regards, Robert
Hi Robert,
It works perfectly
Thnak you very much
Artur
Robert,
This works great. Thanks!
Regards,
Jeff
Thanks RvdNieuwendijk