I am trying to get information using a script modified from that of VMware KB: Cisco Discovery Protocol (CDP) network information but instead of CDP info I need to return the LLDPInfo object instead.
My script does get the info I need, but I am having trouble selecting out just the info I need from the "Parameter" property. I'm having problems figuring out how to deal with the Key/Value pairs stored in the LLDPInfo.Parameter object.
I would like to have an output showing:
$vmh.Name, $hint.DeviceName, $hint.LLDPInfo.Parameter("System Name"), $hint.LLDPInfo.Parameter("Port Description")
example:
vmhost1, vmnic0, hpswitch1, A1
vmhost1, vmnic1, hpswitch2, A1
vmhost2, vmnic0, hpswitch1, B1
vmhost2, vmnic1, hpswitch2, B1
My script:
$vmh = Get-VMHost
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.LLDPInfo ) {
$hint.LLDPInfo.Parameter
}
else {
Write-Host "No LLDP information available."
}
}
}
}
}
Thanks!