Moving VMs between Port Groups

I’m currently running a project to consolidate a sprawl of VM farms which are underutilised, down to a much smaller number, and a significant reduction in host numbers. The first cluster I’ve started work on had a non-standard naming convention for the Port Groups, so prior to moving this needs correcting.

First I’ve added new Port groups with the correct names, then I knocked up a quick PowerCLI script to move all the VMs:

$vms = Get-Cluster "Cluster1" | Get-VM
foreach ($vm in $vms) {
$nics = $vm | Get-NetworkAdapter
 foreach ($nic in $nics) {
 if ( $nic.NetworkName -eq "1st_old_name") {
  Set-NetworkAdapter $nic -NetworkName "1st_new_name" -Confirm:$false
 if ( $nic.NetworkName -eq "2nd_old_name") {
  Set-NetworkAdapter $nic -NetworkName "2nd_new_name" -Confirm:$false

This cycles through each of the VMs in the cluster, and moves each adapter on the old name to the new name.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s