You dont have javascript enabled! Please enable it!

How To Migrate Virtual Machines From One Logical Switch To Another Logical Switch in Virtual Machine Manager?

3 Min. Read

Hello folks,

A few blogs ago I showed you how to migrate from Standard Virtual Switch to Logical Switch in Virtual Machine Manager.

In today’s post I will show you how to migrate your virtual machines from an existing logical switch to another logical switch.

But before start doing that, let’s see in what scenario you might require this migration.

Scenarios

1- You have upgraded your Hyper-V host with higher network adapters and now you want to move all your VMs workload over the new NICs.

2- You are using converged virtual network within Hyper-V deployments that is managed by System Center Virtual Machine Manager, and now you need to move all your VMs traffic off the converged vSwitch and use a dedicated logical switch.

More information on how to create a Logical Switch in VMM.

In order to move your virtual machine from one logical switch to another one is very simple.

To choose a logical switch

Open the VM and Services workspace.
Choose any host group, and then select the desired virtual machine.
On the Virtual Machine tab, click Properties.
The Virtual Machine window properties opens.
Choose the Hardware Configuration, and then browse to Network Adapters.
Select the desired Virtual Network Adapter, and then change the Logical Switch as showing in below figure.

VMM-LS01

Select the Logical Switch for virtual machines in VMM. (Image Credit: Charbel Nemnom)

Now the challenge is, what if you need to migrate 50 VMs and each VM has multiple vNICs and each is on different VLAN? 

Because when you change the Logical Switch in the UI, you need to select again the port classification and enable the VLAN ID.

VMM-LS02

Changing the Logical Switch for virtual machines in VMM. (Image Credit: Charbel Nemnom)

This indeed a long homework! Crying face

So what is the solution then?

The answer is PowerShell of course Winking smile

I have created the following tool that will help you to migrate all Virtual Machines on a particular Hyper-V host from an existing logical switch to another logical switch, while preserving all the existing configuration:

VMM-LS03

<#
 .SYNOPSIS
Migrating Virtual Machines from Logical Switch to another Logical Switch in Virtual Machine Manager.

.DESCRIPTION
Migrating Virtual Machines from Logical Switch to another Logical Switch in Virtual Machine Manager.

.NOTES
File Name : VMM-LSMigration.ps1
Author    : Charbel Nemnom
Date      : 15-04-2020
Version   : 1.1
Requires  : PowerShell Version 3.0 or above
OS        : Windows Server 2012, 2012 R2, 2016, 2019
Component : System Center Virtual Machine Manager 2012 R2, 2016, 2019

.LINK
To provide feedback or for further assistance please visit:
Cover Page
.EXAMPLE ./VMM-LSMigration -VMMServerName <VMMServerName> -HostName <HyperVHostName> This example will migrate all virtual machines on <HyperVHostName> from an existing Logical Switch to another Logical Switch. #> [CmdletBinding()] param( [Parameter(Mandatory=$true, HelpMessage='VMM Server Name')] [Alias('VMMServer')] [String]$VMMServerName, [Parameter(Mandatory=$true, HelpMessage='Hyper-V Host Name')] [Alias('HVHost')] [String]$HostName ) # Get All Virtual Machines $VMs=Get-SCVirtualMachine -VMHost $HostName # Get all the existing Virtual Machines vmNICs and logical switches foreach ($VM in $VMs) { Get-SCVirtualNetworkAdapter -VM $VM.Name | ft Name, VirtualNetwork, PortClassification, VLanID -AutoSize } # Select the Logical Switch that you want to move to $VirtualNetwork=Get-SCLogicalSwitch -VMMServer $VMMServerName | Out-Gridview -PassThru -Title 'Select Logical Switch' # Migrate all VMs to the new Logical Switch foreach ($VM in $VMs) { $NICs=Get-SCVirtualNetworkAdapter -VMMServer $VMMServerName -VM $VM.Name $CountedNics = $NICs.Count for ($i=0; $i -lt $CountedNics ; $i++) { $PortClassification = $NICs[$i].PortClassification Set-SCVirtualNetworkAdapter -VirtualNetworkAdapter $NICs[$i] -VirtualNetwork $VirtualNetwork -PortClassification $PortClassification } } # Refresh the Hyper-V Host in VMM! Get-SCVMHost $HostName | Read-SCVMHost # Verifiy vmNICs on all Virtual Machines that are moved to the new Logical Switch foreach ($VM in $VMs) { Get-SCVirtualNetworkAdapter -VM $VM.Name | ft Name,VirtualNetwork,PortClassification,VLanID -AutoSize -Wrap } # End # Enjoy :)

Do you have any other scenarios? please feel free to leave a comment below.

Hope this helps!

Cheers,
-Charbel

Photo of author
About the Author
Charbel Nemnom
Charbel Nemnom is a Senior Cloud Architect, Swiss Certified ICT Security Expert, Certified Cloud Security Professional (CCSP), Certified Information Security Manager (CISM), Microsoft Most Valuable Professional (MVP), and Microsoft Certified Trainer (MCT). He has over 20 years of broad IT experience serving on and guiding technical teams to optimize the performance of mission-critical enterprise systems with extensive practical knowledge of complex systems build, network design, business continuity, and cloud security.
Previous

StarWind V2V Converter Update, Newly Released Technical Paper, Tap Room Meeting, and Free Webinar #StarWind #HyperV

Review: Windows Server 2012 R2 Administrator Cookbook @PacktPub #WS2012R2 #WindowsServer

Next

Let me know what you think, or ask a question...

error: Alert: The content of this website is copyrighted from being plagiarized! You can copy from the 'Code Blocks' in 'Black' by selecting the Code. Thank You!