VMware Cloud Community
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Observed IP Ranges

Hi,

Is it possible to get the 'Observed IP Ranges' for each nic in each host, couldnt find where it was recorded ?!

Thanks

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

When you have more than 1 ESX server the script becomes a bit more complex.

Try this:

$networkSystem = Get-VMHost | Get-View | %{Get-View $_.ConfigManager.NetworkSystem}
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
	  }
	}
  }
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
10 Replies
ykalchev
VMware Employee
VMware Employee
Jump to solution

It's located in ipSubnet property of the PhysicalNicIpHint. You can get PhysicalNicIpHint object from HostNetworkSystem.QueryNetworkHint()

$h = Get-VMHost | Get-View
$networkSystem = Get-View $h.ConfigManager.NetworkSystem
$networkSystem.NetworkConfig.Pnic | %{$networkSystem.QueryNetworkHint($_.device)} |%{$_.Subnet}

Regards,

Yasen

Yasen Kalchev, vSM Dev Team
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Thanks, Unfortunatly Im getting the following error:

Get-View : The argument cannot be null or empty.<br /><br/>
At C:\DOCUME~1\me\LOCALS~1\Temp\1\28cc7d0d-6c96-4307-b748-2552ba12c58f.ps1:<br/><br/>
3 char:26<br/><br/>
+ $networkSystem = Get-View  &lt;&lt;&lt;&lt; $h.ConfigManager.NetworkSystem<br/><br/>
You cannot call a method on a null-valued expression.<br/><br/>
At C:\DOCUME~1\me\LOCALS~1\Temp\1\28cc7d0d-6c96-4307-b748-2552ba12c58f.ps1:<br/><br/>
4 char:70<br/><br/>
+ $networkSystem.NetworkConfig.Pnic | %{$networkSystem.QueryNetworkHint( &lt;&lt;&lt;&lt; $<br/><br/>
_.device)} |%{$_.Subnet}

</p>

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

When you have more than 1 ESX server the script becomes a bit more complex.

Try this:

$networkSystem = Get-VMHost | Get-View | %{Get-View $_.ConfigManager.NetworkSystem}
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
	  }
	}
  }
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Amazing as always LucD

Thanks.

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

It's probably useful to list the ESX hostname as well.

$esxList = Get-VMHost | Get-View
foreach($esx in $esxList){
	Write-Host $esx.Name
	$networkSystem = Get-View $esx.ConfigManager.NetworkSystem
	foreach($netSys in $networkSystem){
		foreach($pnic in $netSys.NetworkConfig.Pnic){
			Write-Host 
			$subnets = $netSys.QueryNetworkHint($pnic.Device)
			foreach($pnichint in $subnets){
				Write-Host "`t" $pnichint.Device
				foreach($pniciphint in $pnichint.Subnet){
					Write-Host "`t`t" $pniciphint.IpSubnet
				}
			}
		}
	}
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
alanrenouf
VMware Employee
VMware Employee
Jump to solution

ha ha snap !

$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
				}
			}
		}
	}
}

Alan

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Scary, the twilight zone Smiley Wink


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Du du du du, Du du du du (sounded better in my head !)

Ok, just had a request to add the Cisco Discovery Protocol Info, any ideas where the info is stored ?

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

See .


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Thanks LucD Didnt search for that one Smiley Happy

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
Reply
0 Kudos