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
}
}
}
}
}
how to export this script to csv file.
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