Something seems a bit amiss here; on a vSphere 5.5 installation, querying a traditional vSwitch (ie not dvSwitch) for portgroups I am not receiving the expected object array of type VcHostPortGroup [], but rather a flat string array that cannot be expanded.
This seems to break the supplied actions for listing portgroups as well as my own code, so I suspect that some change in the 5.5 API may have gone unnoticed since so few people use vSwitches any more.
Could someone check the following code and see what happens:
var hosts=Server.findAllForType("VC:HostSystem"); var host=hosts[0]; var switches=host.configManager.networkSystem.networkInfo.vswitch; for (var i=0; i<switches.length; i++) { vswitch=switches[i]; System.log(vswitch); var pglist=vswitch.portgroup; for (var n=0;n<pglist.length;n++) { var pg=pglist[n]; System.log (pg); System.log("Found portgroup "+ pg.spec.name +" with vlan ID "+pg.spec.vlanId); // This breaks } }