Thursday, January 27, 2011

vCO - get all Distributed Virtual Switches

Yesterday i try to get all dvSwitches of a vCenter environment into an array. After several hours of searching and trying there is no easy way in my opinion. So i think this little workaround could help:

var dvPG = VcPlugin.getAllDistributedVirtualPortgroups();
var DVS = new Array(); 

for(i in dvPG){
   System.log("DVS vor Schleife: " + DVS);

   for ( i = 0; i < DVS.length; i++)
      if(i != 0){
      while (DVS[i] == DVS[i-1])

If you have other ways please feel free to publish them as a comment. Please note that you need at least one dvPortGroup!


  1. If there is no portgroup, array dvPG is initialized with length 0 and so the for-loop is passed by. DVS array is initialized with lenght 0.
    So this task will also run (correct) if there is no dvPortGroup, assuming the DVS is set as output parameter.

  2. Million thanks..impressed with the stuff here.


  3. For some reason I cannot post code as a reply. I am trying now with a link to wordpress on how I think is another approach of getting all the Distributed Virtual Switches without running through all port groups.

    Hope you like it.

  4. I know it's an old post but I ran into the same challenge today. Here is my solution.
    var allDvs = Server.findAllForType("VC:VmwareDistributedVirtualSwitch");

    you can filter down from there. like this:
    var targetDvs = allDvs.filter(function(dvs) {
    return ==

    targetVc is an VcSdkConnection but you could filter on other stuff as well.