Jun 252013
 

If your hosts can see the CDP info from your physical network, this will help check or map your port configs.

$Clustername = “hotness”
$report = @()
$allhosts = get-cluster $Clustername | get-vmhost
foreach($singlehost in $allhosts){
Get-VMHost $singlehost | Where-Object {$_.State -eq “Connected”} |
%{Get-View $_.ID} |
%{$esxname = $_.Name; Get-View $_.ConfigManager.NetworkSystem} |
%{foreach($physnic in $_.NetworkInfo.Pnic){
$pnic = $_.QueryNetworkHint($physnic.Device)
foreach($thing in $pnic){
$ReportRow = “” | select Hostname,vmnic,Ttl,Samples,DevId,Address,PortId,HardwarePlatform,Vlan,FullDuplex,Mtu
if( $thing.ConnectedSwitchPort ) {
$reportRow.Hostname = $esxname
$reportRow.vmnic = $physnic.Device
$reportRow.Ttl = $thing.ConnectedSwitchPort.ttl
$reportRow.Samples = $thing.ConnectedSwitchPort.samples
$reportRow.DevId = $thing.ConnectedSwitchPort.Devid
$reportRow.Address = $thing.ConnectedSwitchPort.address
$reportRow.PortId = $thing.ConnectedSwitchPort.portid
$reportRow.HardwarePlatform = $thing.ConnectedSwitchPort.HardwarePlatform
$reportRow.Vlan = $thing.ConnectedSwitchPort.vlan
$reportRow.FullDuplex = $thing.ConnectedSwitchPort.fullduplex
$reportRow.Mtu = $thing.ConnectedSwitchPort.mtu
}}$report += $reportrow}}}

 Then you can “export-csv”  the $report var or just throw it on the command line to see the output.