posted

12 Comments

Recently someone asked me if there was a way, programmatically, to figure out the “observed IP ranges” and “observed VLANs’” that you can see in vSphere Client. Don’t know what I mean? Here’s a picture to help you out.

vlans

The data is available as a tooltip in the network configuration tab (naturally!) when you hover over Observed IP Ranges. How do you get this stuff out of the API.

Turns out there’s a rather obscure little function called QueryNetworkHint. This function takes the name of the physical NIC as input, which makes it perfect for pairing with our Get-VMHostNetworkAdapter cmdlet. Here’s a PowerShell advanced function that does exactly that, followed by some screenshots of it in action.

 

Let’s have a look at that in action. First some basic usage, combining Get-VMHost, Get-VMHostNetworkAdapter and the Get-ObservedIPRange advanced function.

blog1

Comparing these to the screenshot above you’ll see they’re the same. Let’s take it a step further and suppose we want to determine if a certain adapter can see a certain VLAN, let’s say 2903. Here’s some code that does it:

blog2

This function can really help you out if you use sophisticated networking to your ESX hosts but don’t control the switches directly, so you have to coordinate with a member of the networking team.

Update 1: As a reader kindly pointed out, this will only show VLANs for which the ESX server has seen actual traffic, it will not probe the switch for configuration.

Update 2: The code sample has been updated to fix the type name in the advanced function. The old function used a type name that only worked in internal builds of PowerCLI.