PowerCLI one-liner to rename a PortGroup on an ESX/ESXi host

If having to login to your VMware vSphere infrastructure is a hassle just to rename a PortGroup on a single ESX/ESXi host is a hassle you can run the following PowerCLI one-liner to take care of business:

Get-VMHost -name esx1 | Get-VirtualPortGroup -Name "Inside-VLAN" | Set-VirtualPortGroup -Name "DMZ-VLAN"

The command connects to the ESX/ESXi host called esx1 and renames the PortGroup called Inside-VLAN to DMZ-VLAN.

If the PortGroup being changed is the native vlan on a trunk port then you would not tag it. However, if it was tagged with a vlan id and you were changing your network configuration this could also mean that you want to change the vland id. If so add the -vlanid parameter followed by the id:

Get-VMHost -name esx1 | Get-VirtualPortGroup -Name "Inside-VLAN" | Set-VirtualPortGroup -Name "DMZ-VLAN" -vlanid 1002

Simple as that!