PowerCLI: Mass VM Portgroup Change
I was asked in my Script List if it was possible to change Multiple VMs to attach to a new PortGroup, this task is easy enough so long as you remember that every VM can have up to 4 virtual nics in VI3 and up to 10 in vSphere.
So to change all virtual machines we would do the following:
$OldNetwork = "PG1 192.168.0"
$NewNetwork = "PG2 10.1.1"
Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -eq $OldNetwork } |Set-NetworkAdapter -NetworkName $NewNetwork -Confirm:$false
Or to change all of the VMs for a particular cluster we could use:
$Cluster = "Non-Production"
$OldNetwork = "PG1 192.168.0"
$NewNetwork = "PG2 10.1.1"
Get-Cluster $Cluster |Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -eq $OldNetwork } |Set-NetworkAdapter -NetworkName $NewNetwork -Confirm:$false
Note: By default the Set-NetworkAdapter cmdlet would prompt you for each change it was going to make, this is overwritten by using the –Confirm:$false parameter.
VESI
This can also be achieved from the VESI by:
- Connect to a managed host
- Select Virtual Machines
- Select the virtual machines from the grid view which you would like to change
- Click ‘Network Adapters’ from the links pane on the right
- Filter the grid view to only display the adapters attached to a certain Network Name
- Click ‘Change Properties’ from the Actions pane on the right and enter a new NetworkName as seen below
The VESI 1.2 – Get it now Workstation & Server Audit Script V3











Social comments and analytics for this post…
This post was mentioned on Twitter by alanrenouf: New blog post: PowerCLI: Mass VM Portgroup Change http://bit.ly/3UinOJ...
Awesome! Totally awesome!! Thanks!@
What if i had to change only the name of the portgroup, for example from a to b, the minute i change it in the host level, all the vm’s will lose the network, will this script still work? or it will fail to get the old network?
Hi there,
VESI’s site seems to be redirecting to [http://www.powergui.org/index.jspa]
Is it the same software?
btw, love your scripts!!!!!!!
Yes, VESI has now been discontinued and replaced by PowerGUI.