PowerCLI one-liner to rename a PortGroup on all ESX/ESXi hosts in a cluster

It can be a huge hassle to manually rename PortGroups across multiple ESX/ESXi hosts in a cluster. This is where PowerCLI becomes super handy – the one-liner below will take of it:

Get-Datacenter London-DC | Get-Cluster "ESX Cluster" | Get-VMHost | Get-VirtualPortGroup -Name "Inside-VLAN" | Set-VirtualPortGroup -Name "DMZ-VLAN" -vlanid 1002

The above command connects into the London-DC Datacenter object and then to the Cluster ESX Cluster. It will get all the ESX/ESXi servers in the cluster by running Get-VMHost. It then locates the PortGroup called Inside-VLAN and renames it to DMZ-VLAN and tags it with vlan ID 1002.

If you have upwards of 5 ESX/ESXi hosts it will save you a lot of time and effort.