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)"
$i++
}
$selection = Read-Host "Please make a selection (Q to Quit)"
if($selection -eq 'Q'){
clear

}
else{
$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 ) {
$hint.ConnectedSwitchPort
}
}
}
}
Write-Host -NoNewLine " Press any key to continue…";
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
clear
}
}

 320 total views,  2 views today

Leave a Reply

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