Skip navigation

In a most of the vmware infrastructure environment we are using stndard vswitches . the limitation is the standard vsiwtch is when we are doing any modification and when we are creating vswitches, we have to do it manually an individually. If we have multiple port groups its a very difficult this. To avoid this thing, we can use vmware distirbuted switch. but we need to purchase enterprise plus license. To simplify this process i have created small power-shell script. I will explain this script by using my example.


i have two esxi host and esx-01. corp.local is already configured with required port groups. now we need to create all the port groups in esx-02. corp.local . therefore first i have created vswitch0 in esx-02. Then Using my scrript i can create all the port groups same as esx-01





Connect-ViServer vcsa-01a.corp.local  # Connect to Vcenter Server

$strvswitchonhost02=get-virtualswtich -name vswitch0 -vmhost esx-02a.corp.local  # Host 01 have virtual switch named vswitch0, we have to create same switch in host 02. Its already created and $strvSwitchonhost02 variable store that details

$strsovirprgrp= get-virtualporggropu -vmhost esx-01a.corp.local -virtualswitch vswitch0 -standard # Store all the virtual port details in a $strsovirprgrp array


For ($a=0 ; $a -le $intcount-1 ; $a++)




New-virtualporggroup -virtualSwitch $strvswitchonhost02 -name $strname -VLANId  $intvlan # create virtual port group/s on second host