If you need to create 5 or more of Virtual Port groups on a vSwtich and you don’t want to use the VI client than logon on the service console and run the commands below.

For creating a new Virtual Port Group use:

esxcfg-vswitch -A NAME-TO-GIVE vSwitch0

Assigning a special VLAN to this a Virtual Port Group:

esxcfg-vswitch -v VLANID -p PORTGROUP vSwitch0

With these two simple commands I was able to push my sh script and create same “Networking” configuration on dozen of my ESX servers.

[root@ESX-02 root]# esxcfg-vswitch -A VLAN282 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -A VLAN283 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -A VLAN284 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -A VLAN285 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -A VLAN299 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -A VLAN220 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -v 282 -p VLAN282 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -v 283 -p VLAN283 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -v 284 -p VLAN284 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -v 285 -p VLAN285 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -v 299 -p VLAN299 vSwitch0
[root@ESX-02 root]# esxcfg-vswitch -v 220 -p VLAN220 vSwitch0

esxcfg-vswitch [options] [vswitch[:ports]]

-a|–add Add a new virtual switch.

-d|–delete Delete the virtual switch.

-l|–list List all the virtual switches.

-L|–link=pnic Set pnic as an uplink for the vswitch.

-U|–unlink=pnic Remove pnic from the uplinks for the vswitch.

-M|–add-pg-uplink Add an uplink to the list of uplinks for a portgroup

-N|–del-pg-uplink Delete an uplink from the list of uplinks for a portgroup

-p|–pg=portgroup Specify a portgroup for operation

Use ALL to set VLAN IDs on all portgroups

-v|–vlan=id Set vlan id for portgroup specified by -p

0 would disable the vlan

-c|–check Check to see if a virtual switch exists.

Program outputs a 1 if it exists, 0 otherwise.

-A|–add-pg=name Add a new portgroup to the virtual switch.

-D|–del-pg=name Delete the portgroup from the virtual switch.

-C|–check-pg=name Check to see if a portgroup exists. Program

outputs a 1 if it exists, 0 otherwise.

-B|–set-cdp Set the CDP status for a given virtual switch.

To set pass one of “down”, “listen”, “advertise”, “both”.

-b|–get-cdp Print the current CDP setting for this switch.

-m|–mtu=MTU Set MTU for the vswitch.

-r|–restore Restore all virtual switches from the configuration file

(FOR INTERNAL USE ONLY).

-h|–help Show this message.