Set up a VMware vSwitch – the vMA way

Have a set of new VMware hosts you need to configure matching vSwitch configurations on?

Have a cluster that needs updating with some new VLAN additions on a standard vSwitch?

If you answered ‘yes’ to either of those questions then continue reading!

In this script, we will loop through requesting the password from the user for each host (if each host has differing root passwords), or if you have vifp set up then use the vifptarget command for credentials.

Create a text file with either host names or IP addresses like so:

and we will use this as input to the for loop.

But we still need vmkernel interfaces added and this isn’t as scriptable unless you have your servers set up with a known numbering scheme and it is easy to figure out the pattern to script, here are the command lines used to add vmkernel interfaces for the port groups above.

Easy and simple to edit for your needs.

I used the above script fragments to create standard port groups on the default vSwitch0 when I rolled out my last VMware cluster then converted the vmkernel networking from standard to vDS via the vSphere client.

If you want to do the same for a vSphere Distributed Switch then you’ll need to hop on over to PowerCLI and load a 3rd party module (as of 5.x that is, where x < 5 at the time of this article, or using PowerCLI 5.1 R2 which was recently released). I have used this multiple times for another customer to set up their networking for VXLAN + VLAN + vCloud Director configuration(s).

Leave me a comment if you would like to see the same script via PowerCLI.