It could be very handy to know to what switch, what switch port your esxi network adapters are connected. There is no standard method in PowerCLI with name &#8220;Get-VMHostNetworkAdapterCDP&#8221;. To make it available you need in Powershell ISE import all powerCLI modules and press enter or use below script (replace vcsa by your own server fqdn): &nbsp; .'C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1' connect-viserver vcsa.itforce.local function Get-VMHostNetworkAdapterCDP { &lt;# .SYNOPSIS Function to retrieve the Network Adapter CDP info of a vSphere host. .DESCRIPTION Function to retrieve the Network Adapter CDP  <span><a href="https://www.itforce.mn/index.php/2019/01/31/how-to-get-cdp-information-for-all-esxi-network-adapters/" class="readmore">Continue reading &rarr;</a></span>{"id":1403,"date":"2019-01-31T20:20:48","date_gmt":"2019-01-31T12:20:48","guid":{"rendered":"https:\/\/www.itforce.mn\/?p=1403"},"modified":"2021-04-30T09:20:37","modified_gmt":"2021-04-30T01:20:37","slug":"how-to-get-cdp-information-for-all-esxi-network-adapters","status":"publish","type":"post","link":"https:\/\/www.itforce.mn\/index.php\/2019\/01\/31\/how-to-get-cdp-information-for-all-esxi-network-adapters\/","title":{"rendered":"How to get CDP information for all esxi network adapters"},"content":{"rendered":"<p>It could be very handy to know to what switch, what switch port your esxi network adapters are connected.<\/p>\n<p>There is no standard method in PowerCLI with name &#8220;Get-VMHostNetworkAdapterCDP&#8221;.<br \/>\nTo make it available you need in Powershell ISE<br \/>\n <a href=\"http:\/\/www.itforce.mn\/index.php\/2019\/01\/31\/how-to-import-powercli-modules-into-standard-powershell-ise\/\">import all powerCLI modules<\/a>\u00a0and\u00a0press enter<br \/>\nor use below script (replace vcsa by your own server fqdn):<\/p>\n<p>&nbsp;<\/p>\n<pre>\r\n.'C:\\Program Files (x86)\\VMware\\Infrastructure\\PowerCLI\\Scripts\\Initialize-PowerCLIEnvironment.ps1'\r\n<br>\r\nconnect-viserver vcsa.itforce.local\r\n<br>\r\nfunction Get-VMHostNetworkAdapterCDP {\r\n&lt;# .SYNOPSIS Function to retrieve the Network Adapter CDP info of a vSphere host. .DESCRIPTION Function to retrieve the Network Adapter CDP info of a vSphere host. .PARAMETER VMHost A vSphere ESXi Host object .INPUTS System.Management.Automation.PSObject. .OUTPUTS System.Management.Automation.PSObject. .EXAMPLE PS&gt; Get-VMHostNetworkAdapterCDP -VMHost ESXi01,ESXi02\r\n\r\n .EXAMPLE\r\n PS&gt; Get-VMHost ESXi01,ESXi02 | Get-VMHostNetworkAdapterCDP\r\n\r\n#&gt;\r\n[CmdletBinding()][OutputType('System.Management.Automation.PSObject')]\r\n\r\nParam\r\n (\r\n\r\n[parameter(Mandatory=$true,ValueFromPipeline=$true)]\r\n [ValidateNotNullOrEmpty()]\r\n [PSObject[]]$VMHost\r\n )\r\n\r\nbegin {\r\n\r\n $ErrorActionPreference = 'Stop'\r\n Write-Debug $MyInvocation.MyCommand.Name\r\n $CDPObject = @()\r\n }\r\n\r\nprocess{\r\n\r\ntry {\r\n foreach ($ESXiHost in $VMHost){\r\n\r\nif ($ESXiHost.GetType().Name -eq \"string\"){\r\n\r\n try {\r\n $ESXiHost = Get-VMHost $ESXiHost -ErrorAction Stop\r\n }\r\n catch [Exception]{\r\n Write-Warning \"VMHost $ESXiHost does not exist\"\r\n }\r\n }\r\n\r\n elseif ($ESXiHost -isnot [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl]){\r\n Write-Warning \"You did not pass a string or a VMHost object\"\r\n Return\r\n }\r\n\r\n$ConfigManagerView = Get-View $ESXiHost.ExtensionData.ConfigManager.NetworkSystem\r\n $PNICs = $ConfigManagerView.NetworkInfo.Pnic\r\n\r\nforeach ($PNIC in $PNICs){\r\n\r\n$PhysicalNicHintInfo = $ConfigManagerView.QueryNetworkHint($PNIC.Device)\r\n\r\nif ($PhysicalNicHintInfo.ConnectedSwitchPort){\r\n\r\n$Connected = $true\r\n }\r\n else {\r\n $Connected = $false\r\n }\r\n\r\n$hash = @{\r\n\r\n VMHost = $ESXiHost.Name\r\n NIC = $PNIC.Device\r\n Connected = $Connected\r\n Switch = $PhysicalNicHintInfo.ConnectedSwitchPort.DevId\r\n HardwarePlatform = $PhysicalNicHintInfo.ConnectedSwitchPort.HardwarePlatform\r\n SoftwareVersion = $PhysicalNicHintInfo.ConnectedSwitchPort.SoftwareVersion\r\n ManagementAddress = $PhysicalNicHintInfo.ConnectedSwitchPort.MgmtAddr\r\n PortId = $PhysicalNicHintInfo.ConnectedSwitchPort.PortId\r\n\r\n}\r\n $Object = New-Object PSObject -Property $hash\r\n $CDPObject += $Object\r\n }\r\n }\r\n }\r\n catch [Exception] {\r\n\r\n throw \"Unable to retrieve CDP info\"\r\n }\r\n }\r\n end {\r\n\r\n Write-Output $CDPObject\r\n }\r\n}\r\n\r\nget-vmhost | Get-VMHostNetworkAdapterCDP | Select-Object VMHost, NIC, Switch, PortID, connected, ManagementAddress,HardwarePlatform | Export-Csv -notypeinformation -Path c:\\temp\\cdp.csv\r\n\r\n<\/pre>\n<p>ps:<\/p>\n<p>if you need this function and one-liner regularly you can add function into powershell profile and run as alias.<\/p>\n","protected":false},"excerpt":{"rendered":null,"protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-1403","post","type-post","status-publish","format-standard","hentry","category-powercli"],"_links":{"self":[{"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/posts\/1403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/comments?post=1403"}],"version-history":[{"count":20,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/posts\/1403\/revisions"}],"predecessor-version":[{"id":1630,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/posts\/1403\/revisions\/1630"}],"wp:attachment":[{"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/media?parent=1403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/categories?post=1403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itforce.mn\/index.php\/wp-json\/wp\/v2\/tags?post=1403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}