Change VLAN of a PortGroup in VMware

We recently had a need to change the VLAN of a port group in our ESX clusters. We could have run the sync script to replicate all the changes, but that potentially touches so much that I didnt want too. I instead used the below commands in powershell to search for a port group and then change the VLAN.

$ESXHosts = Get-VMHost
foreach ($ESXHost in $ESXHosts){
$VirtualSwitches = Get-VirtualSwitch -VMHost $ESXHost
foreach ($VirtualSwitch in $VirtualSwitches){
$VirtualPortGroups = Get-VirtualPortGroup -VirtualSwitch $VirtualSwitch
foreach ($VirtualPortGroup in $VirtualPortGroups){
if (($VirtualPortGroup).Name -eq “portgroup_25”) {
write-host $VirtualPortGroup.Name
write-host $VirtualPortGroup.VLanId
#Set-VirtualPortGroup -VirtualPortGroup $VirtualPortGroup -VLanId 25

Leave a Reply