VMWare PowerCli copy all the standard switch port groups to the new host/s

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

3

 

 

 

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

$intcount=$strsovirprgrp.count 

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

{

$strname=$strsovirprgrp[$a].name

$intvlan=$strsovirprgrp[$a].VLANID

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

}

4

 

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: