How To Migrate Virtual Machines From One Logical Switch To Another Logical Switch in Virtual Machine Manager? #SCVMM #SysCtr #HyperV

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.


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.


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.


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:


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

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

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

To provide feedback or for further assistance please visit:

./VMM-LSMigration -VMMServerName <VMMServerName> -HostName <HyperVHostName>
This example will migrate all virtual machines on <HyperVHostName> from an existing Logical Switch to another Logical Switch.

[Parameter(Mandatory=$true, HelpMessage='VMM Server Name')]

[Parameter(Mandatory=$true, HelpMessage='Hyper-V Host Name')]

# 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!


About Charbel Nemnom 578 Articles
Charbel Nemnom is a Cloud Architect, Swiss Certified ICT Security Expert, Microsoft Most Valuable Professional (MVP), and Microsoft Certified Trainer (MCT), totally fan of the latest's IT platform solutions, accomplished hands-on technical professional with over 17 years of broad IT Infrastructure experience serving on and guiding technical teams to optimize the performance of mission-critical enterprise systems. Excellent communicator is adept at identifying business needs and bridging the gap between functional groups and technology to foster targeted and innovative IT project development. Well respected by peers through demonstrating passion for technology and performance improvement. Extensive practical knowledge of complex systems builds, network design, business continuity, and cloud security.

Be the first to comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.