VMware Powercli: Get CDP infos for the Hosts Networkadapter

Hi,

if CDP is enabled the networkswitches gives some informations to the ESXi Hosts physical network adapters.

Here are the steps to retrive these by PowerCli.

PS D:\> $oVMHost = Get-VMHost -Name myESXiHost.myDomain.org

Get the networkview of the host

PS D:\> $oViewNetSystem = Get-View $oVMHost.ExtensionData.ConfigManager.NetworkSystem

Query the infos for each (physical) LAN adapter on a host. Show only if data are available

PS D:\> Get-VMHostNetworkAdapter -VMhost  $oVMHost -Physical | % { 
    $CDPData=$oViewNetSystem.QueryNetworkHint($_.Name) 
    if($CDPData.ConnectedSwitchPort)
    {
         write-host  -ForegroundColor Green ("Host: {0} CDP Data for {1}" -f $oVMHost.Name, $_.Name )
         $CDPData.ConnectedSwitchPort | fl *
         $CDPData.ConnectedSwitchPort.DeviceCapability | fl *
    }
}

Michael

Leave a Reply