Observed IP Ranges

Recently I needed to check a whole bunch of servers to see if we had a particular VLAN tagged on any of the ESX Hosts, after a quick post on the VI Toolkit forum and a little messing, the following script tells me quickly which observed IP ranges are on each of the nics in each of the hosts…

Connect-VIServer MYVISERVER
$vmhosts = Get-VMHost | Get-View
foreach ($vmhost in $vmhosts)
{
$networkSystem = Get-view $vmhost.ConfigManager.NetworkSystem
Write-Host $vmhost.Name -foregroundcolor yellow
foreach($netSys in $networkSystem)
{
foreach($pnic in $netSys.NetworkConfig.Pnic)
{
$subnets = $netSys.QueryNetworkHint($pnic.Device)
foreach($pnicHint in $subnets)
{
Write-Host $pnicHint.Device
foreach($pnicIpHint in $pnicHint.Subnet)
{
Write-Host "`t" $pnicIpHint.IpSubnet
}
}
}
}
}

2 thoughts on “Observed IP Ranges

  1. Gabrie van Zanten

    Hi
    Can you expand this and read the Cisco Discovery Protocol info? In it you can already find VLAN and Cisco Switch to which the nic is connected. That would be really great.

    Gabrie

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.