Extracting Cisco Discovery Protocol Info

Inspired by Gabe over at GabesVirtual World (Check out his site he has some great posts) I have added the Cisco Discovery Protocol info, its not the nicest looking output but the info is there !

Extracts all info for each ESX host into a text file, don’t forget to change the VI server you are connecting to and the path on lines 1 and 2 of the following script:

Connect-VIServer MYVISERVER
$filename = "c:\VirtualNetworkConfig.txt"
$vmhosts = Get-VMHost | Where-Object {$_.State -eq "Connected"} | Get-View
Write-output (Get-Date) | out-file -encoding ASCII -filepath $Filename
foreach ($vmhost in $vmhosts)
{
$networkSystem = Get-view $vmhost.ConfigManager.NetworkSystem
Write-output $vmhost.Name | out-file -Append -encoding ASCII -filepath $Filename
foreach($netSys in $networkSystem)
{
foreach($pnic in $netSys.NetworkConfig.Pnic)
{
$subnets = $netSys.QueryNetworkHint($pnic.Device)
foreach($pnicHint in $subnets)
{
Write-Output $pnicHint.Device | out-file -Append -encoding ASCII -filepath $Filename
foreach($pnicIpHint in $pnicHint.Subnet)
{
$info = $hint.connectedSwitchPort | Select *
$moreinfo = $hint.connectedSwitchPort.deviceCapability
Write-Output $info | Select * | out-file -Append -encoding ASCII -filepath $Filename
Write-Output $moreinfo | Select * | out-file -Append -encoding ASCII -filepath $Filename
Write-Output "Observed IPRanges: " $pnicIpHint.IpSubnet | out-file -Append -encoding ASCII -filepath $Filename
}
}
}
}
}

2 thoughts on “Extracting Cisco Discovery Protocol Info

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.