A couple of months ago we had to create hundreds of portgroups on a dvSwitch on one of our environments. Doing this manually is pretty tedious, even if you only have to create the portgroup and add a VLAN tag.

In this particular case I also had to set the uplink policy and add two vCenter permissions to each portgroup. This would take ages doing it manually but not with the script I created which is shown below.

It’s an easy script, I could make it fancier and add an input-based variable for the vlan range, distributed vSwitch, usergroups and roles but since it’s pretty static for the environment it’s used for, I kept it simple. If you want to use this script just edit those and you are good to go! Maybe I will update this blogpost in the future with the input-based variant.

Quick and easy creation of portgroups with PowerCLI
Quick and easy creation of portgroups with PowerCLI

As you can see, PowerCLI is very powerful in automating simple but tedious everyday tasks on a VI environment. If you want to know more tips and tricks using PowerCLI visit some other blog posts by clicking on the PowerCLI tag above the post or by clicking the button below!

Share this if you found this interesting.

Leave a Reply

Your email address will not be published. Required fields are marked *