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

A useful one-liner to add a PortGroup to all ESX/ESXi hosts in a cluster:

Get-Cluster "ESX Cluster" | Get-VMHost | Get-VirtualSwitch -Name "vSwitch0" | New-VirtualPortGroup -Name "DMZ-VLAN" -vlanid 1002

It adds a PortGroup called DMZ-VLAN to a VirtualSwitch called vSwitch0 which is tagged with vlan 1002 on all ESX/ESXI hosts in the cluster called ESX Cluster.

PowerCLI one-liner to add PortGroup to a single ESX/ESXi host

A useful one-liner to add a PortGroup to an ESX/ESXi host:

get-vmhost -name esx1 | Get-VirtualSwitch -name vSwitch0 | new-VirtualPortGroup -name "Inside-VLAN" -vlanid 1001

It adds a PortGroup called Inside-VLAN to a VirtualSwitch called vSwitch0 which is tagged with vlan 1001.