PowerCLI: Migrate VM’s to another VLAN/Portgroup

Suppose you have several Virtual Machines in a VLAN of which you decide they should be migrated to a new VLAN because of infrastructural changes in your network. This is only handy if the machines you are about to migrate use to get their network addresses.

The first is to configure all the network adapters of all 's from the old to the new VLAN/Portgroup and the second is to do exactly the same but to shortly disconnect/reconnect the network adapters of the Virtual Machines to initiate a DHCP request for your VM's.

First method:

Get-Cluster "Your Cluster" | Get-VM | Get-NetworkAdapter | Where { $_.NetworkName -eq "Old VLAN" } | Set-NetworkAdapter -NetworkName "New VLAN" –Confirm:$

Second method:

Get-Cluster "Your Cluster" | Get-VM | Get-NetworkAdapter | Where { $_.NetworkName -eq "Old VLAN" } | Set-NetworkAdapter -NetworkName "New VLAN" -Connected:$false | Set-NetworkAdapter -Connected:$True –Confirm:$falsen

When you use the second method the vm's must be powered on!!!!!

Special thanks to: Laurensdekoning

No tags for this post.

Leave a Reply

Translate »