I adapted it to suit my needs:
$Hosts = Get-VMHost | sort -property Name
foreach ($vhost in $Hosts){
$vmh = Get-VMHost -Name $vhost
If ($vmh.State -ne "Connected") {
Write-Output "Host $($vmh) state is not connected, skipping."
}
Else {
Get-View $vmh.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 | select @{n="VMHost";e={$esxname}},@{n="VMNic";e={$physnic.Device}},DevId,PortId
}
}
}
}
}
}
.\VMHostCDPInfo.ps1 | Format-Table -AutoSize |Out-File cdpinfo.txt
It ignores all nics where it cannot retrieve any CDP info from, but other than that, you get a nice list, which you can put with your documentation which looks like:
VMHost VMNic DevId PortId ------ ----- ----- ------ server01 vmnic0 switch01 GigabitEthernet1/25 server01 vmnic10 switch02 GigabitEthernet2/0/31
No comments:
Post a Comment