pages

Showing posts with label Array. Show all posts
Showing posts with label Array. Show all posts

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){
   DVS.push(dvPG[i].config.distributedVirtualSwitch);
   DVS.sort();
   System.log("DVS vor Schleife: " + DVS);

   for ( i = 0; i < DVS.length; i++)
      {
      if(i != 0){
      while (DVS[i] == DVS[i-1])
      DVS.splice(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!