Friday, March 9, 2012

vCO - how to find the vlanID of a dvPortGroup

Today I received an interesting question: "How to find out the VLAN ID of a distributed virtual port group?". At the first moment I think: "No problem, cause the vSphere client can also show the information.".

After several hours and searches in the vSphere API and Onyx I realized that there isn´t any direct method for that :(

So I test the illogical things and enhanced the defaultPortConfig attribute about the vlan attribute... and what should I say: There was an atribute!

After testing if the attribute is part of the VcVmwareDistributedVirtualSwitchVlanIdSpec I was able to check the vlan :)

for(i in dvSwitch.portgroup){
if(dvSwitch.portgroup[i].config.defaultPortConfig.vlan instanceof VcVmwareDistributedVirtualSwitchVlanIdSpec){

This looks like the following screen in the end:

So I hope this helps! By the way, I never had so many failed runs in a row :)


  1. I got it a bit differently, sheer luck that I found out how:
    When you get the object of DvPortGroupObject type (lets call it obj), do this in a workflow code:
    DvPortGroupID =;

    This gives you the ID!! I was so happy when I found it :)

  2. Happen to know if something similar is available in the java API? I looked at objects with similar names but did not find a vlan id anywhere.

  3. I know it should be easy, but I'm new to this and I'm not getting quite what I need.

    How would I retrieve the vlan for a specific distributed portgroup?