Add portgroups on a vswitch is pain in the *ss, but you can use this simple script to get it done. @vExpert #esxi #vswitch @VMware #vCommunity

Hi!

Not everyone are using distributed switches in there vmware enviroment or the licence for host profiles. Some uses ordinary vswitches, like me. And every time I do a reinstall or add new hosts I have alot of vlans to add. You can do it from GUI, but it takes time.

You can use api:s, power shell or something else. But in this case I used a simple script to get this done.

Lets start!

We have an ordinary vswitch

vSwitch0

We have a vswtich that is called vSwitch0

What we wanna do is to add a portgroups and attach a vlan id to those portgroups.

My list of portgroups and ID looks like this. (Demo names)

name= vlan-1 vlan id= 10
name= vlan-2 vlan id= 11
name= vlan-3 vlan id= 11
name= vlan-4 vlan id= 11

create a file named net.sh

and the content of that file looks like this

esxcli network vswitch standard portgroup add -p "vlan-1" -v vSwitch0
esxcli network vswitch standard portgroup set -p "vlan-1" --vlan-id 10
esxcli network vswitch standard portgroup add -p "vlan-2" -v vSwitch0
esxcli network vswitch standard portgroup set -p "vlan-2" --vlan-id 11
esxcli network vswitch standard portgroup add -p "vlan-3" -v vSwitch0
esxcli network vswitch standard portgroup set -p "vlan-3" --vlan-id 12
esxcli network vswitch standard portgroup add -p "vlan-4" -v vSwitch0
esxcli network vswitch standard portgroup set -p "vlan-5" --vlan-id 12

So the first line we add portgroup named vlan-1. The second line we edit that portgroup to add vlan tag to it. And then on to the next port group.

Next step is to apply this on the hosts.

The file you did create copy the file to the esxi host or on any shared volumes that the esxi hosts can see.

Then you need to access the hosts with ssh or from the console.

  1. ssh (or console)
  2. login
  3. run below command (you can do it in other ways, but this worked for me and that is what I put here)
chmod +x /vmfs/volumes/path to a volume/net.sh
then
sh /vmfs/volumes/path to a volume/net.sh

And the ssh to the next server and run that script.

Nice, we have now all our portgroups with vlan attached. And it is nice to have this documented for future installation or reinstalls.

Keep hacking!

//Roger

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.

Blog at WordPress.com.

Up ↑

%d bloggers like this: