For Standard switches and portgroups you can use the inbuilt action:
com.vmware.library.vc.networking: getVSwitchPortgroups
For Distributed switches and portgroups create an action with the following:
IN:
DvSwitch: VC:VmwareDistributedVirtualSwitch
Return type:
VC:DistributedVirtualPortgroup
Code:
var DvPortgroups = DvSwitch.portgroup;
return DvPortgroups
I uploaded a copy of the getDvSwitchPortGroups.action action to GitHub so you don't need to create it yourself.
Blog: http://jonathanmedd.net | Twitter: @jonathanmedd