Listing allowed VLANs on uplinks (vmnic) of ESXi 5.1 hosts

ESXi 5.1 has the ability to show  allowed VLANs on  physical NICs (vmnic). By default this option is not enabled on NICs. We have to enable explicitly and gather the VLAN details. Please find the script below which will help you to enable the VLAN STATS on the NICs which have the LINK status UP.

[crayon lang=”powershell”]
# Script for listing the allowed VLANS on physcical NICs of the ESXi Host.
Connect-VIServer  <vCenter Server>

$HostName= <ESXi Host Name or IP>
$esxcli = Get-EsxCli -VMHost $HostName

$ | Where-Object {$_.Link -eq”Up”} | %{
$vmnic_name = $_.Name
($$vmnic_name) | Select -expand vlanid) -join’,’
Write-Host VLAN stats are disabled for $vmnic_name. Enabling it now..

# I have observed there is a delay taken by host to generate the complete list of VLANs. So its preferred to put a minute of delay before fetching the details.

Start-Sleep-Seconds 60

($$vmnic_name) | Select -expand vlanid) -join’,’

Sample output:

VLAN stats are disabled for vmnic2 . Enabling it now..



VLAN stats are disabled for vmnic3 . Enabling it now..