List all hosts in a cluster then pull the CDP Information

The function “VP-HostCDPInfo” will list all hosts in cluster $Global:CLUChoice from DC $Global:DCChoice, you can then select a host and list its CDP information for each NIC

Get host CDP Information
function VP-HostCDPInfo
$hosts = Get-datacenter $Global:DCChoice | Get-Cluster $Global:CLUChoice | get-vmhost
Write-Host "================ Select host ================"
$i = 1
$hosts | ForEach-Object -Process {
Write-Host "$i $($_.Name)"
$selection = Read-Host "Please make a selection (Q to Quit)"
if($selection -eq 'Q'){

$HostChoice = $hosts[$selection -1].Name
Get-VMHost $HostChoice |
%{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
if( $hint.ConnectedSwitchPort ) {
Write-Host -NoNewLine " Press any key to continue…";
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.