Do my ESXi hosts have the same VLANs?

In a small vSphere environment that I’ve recently been working on, I started to notice that some of my VMs were disappearing off the network from time to time. Reboots of the VM didn’t seem to fix the issue but a quick vMotion of the VM to another host did.

If you haven’t figured it out yet, one of my hosts was missing a VLAN and VMs connected to a certain portgroup were affected whenever they ran on the host.

vSphere will warn you if a host that you’re trying to migrate a VM to doesn’t have the right portgroup and host profiles (if you’re using Enterprise Plus licensing) will alert you to the fact that a portgroup isn’t configured with the right VLAN ID but nowhere in vSphere will you get an alert if a required VLAN is not being presented to a host. So you have to use other means to check this information.

You could manually examine the properties of each physical NIC in turn but that could take some time. The method that I used on this occasion was a PowerCLI script. I could have written one myself but a quick google lead me to a script written by Luc Dekens that did what I wanted already (and a little more besides). I modified it to suit my needs (demonstrating to the person in the remote datacenter that there was a network misconfiguration) and ran it. The output is below:

[ps]Host: esx1.mydomain.com

vmnic0 VLAN224 VLAN227

vmnic1 VLAN224 VLAN227

vmnic2 VLAN250 VLAN252 VLAN251

vmnic3 VLAN250 VLAN252 VLAN251

Host: esx2.mydomain.com

vmnic0 VLAN227 VLAN226 VLAN224

vmnic1 VLAN227 VLAN226 VLAN224

vmnic2 VLAN251 VLAN252 VLAN250

vmnic3 VLAN251 VLAN252 VLAN250

Host: esx3.mydomain.com

vmnic0 VLAN224 VLAN227 VLAN226

vmnic1 VLAN224 VLAN227 VLAN226

vmnic2 VLAN250 VLAN252 VLAN251

vmnic3 VLAN250 VLAN252 VLAN251

Host: esx4.mydomain.com

vmnic0 VLAN224 VLAN226

vmnic1 VLAN224 VLAN226

vmnic2 VLAN250 VLAN251

vmnic3 VLAN250 VLAN251 VLAN252[/ps]

As you can see, there are some discrepancies in which VLANs are presented to the four hosts that I ran it against and vmnic2 on Host4 was the one causing my problems. The hosts are supposed to have the vmnics paired (vmnic0/vmnic1 in one pair and vmnic2/vmnic3 in another) with identical configuration between the hosts.

The modified script that I used is attached below. Many thanks, as always, LucD.