Many organizations are using the benefits of Distributed vSwitches (DVS) for simplified network management. However, there are still a lot of standard vSwitches being used. With VLAN segmentation being common, portgroups are being used as a representation of VLANs on standard vSwitches. Creating new portgroups manually can easily lead to errors, especially if the task has to be done on many hosts.
I wrote a PowerCLI function called New-Portgroup. This makes it possible to create portgroups targeting datacenter, cluster or host objects. You probably don’t need to run this targeting single hosts, but it is possible. You need to have a standardized vSwitch-setup for this to work, meaning that the switches need to be similar in regard to names across the hosts (e.g. vSwitch1)
To use the function, start PowerCLI (or run PowerCLI in ISE if you prefer), and connect to your vCenter-server.
To load the function, remember to dot-space-dot-backslash. You can also add it to your profile script to load it on PowerCLI startup instead of manually loading it as shown in the picture below:
After the function is loaded, you can run it as a normal cmdlet. Use TAB for autocompletion, including the options for the Target-parameter.
Fully written out, it can look something like this:
Creating a portgroup named “test” with VLAN ID 32 on 9 hosts gives the following output:
Use the built-in help function for a description of the parameters, and a couple of examples.
Get the script here https://raw.githubusercontent.com/chralex80/Scripts/master/New-Portgroup.ps1