Sergey Nivens - Fotolia

How do you reconnect a Hyper-V virtual switch to your VMs?

Save time by using PowerShell commands to reconnect your VMs to a new Hyper-V virtual switch. Different commands can access single VMs or many VMs whether they are local or remote.

It can be time-consuming to reconnect VMs to a new Hyper-V virtual switch, but with a few PowerShell commands, you can reconnect local or remote VMs and verify that connection.

When you replace a physical network adapter on a Hyper-V host, you'll need to create a new Hyper-V virtual switch. This requires that you disconnect the Hyper-V virtual switch from the physical network adapter. The virtual switch will also disconnect from the VMs that were using it. Set aside time to install the new physical adapter, create a new virtual switch, map the virtual switch to the new physical network adapter and assign the new virtual switch to VMs.

The process of reconnecting VMs to the new Hyper-V virtual switch can take a significant amount of time, but PowerShell can make it efficient to reconnect VMs. This is especially strenuous if you need to connect multiple VMs or if the VMs are on remote Hyper-V hosts, but PowerShell helps with this, too.


Use commands to make a new
Hyper-V VM.

Use the Connect-VMNetworkAdapter PowerShell cmdlet to connect VMs to a Hyper-V virtual switch. In this example, assume that you have a Hyper-V virtual switch named ProductionVSwitch and you'd like to connect this switch to VMs running on local or remote Hyper-V hosts.

To connect a single VM to a new Hyper-V virtual switch, execute this PowerShell command:

Get-VM "SQLVM" | Get-VMNetworkAdapter | Connect-VMNetworkAdapter -SwitchName "ProductionVSwitch"

To connect all the VMs running on a local Hyper-V host to a new virtual switch, use this PowerShell command:

Get-VM | Get-VMNetworkAdapter | Connect-VMNetworkAdapter -SwitchName "ProductionVSwitch"

These PowerShell commands only work for a local Hyper-V host. Use the following PowerShell command to connect a new virtual switch to all the VMs running on a remote Hyper-V host.

Get-VM * -ComputerName HyperVHost1 | Get-VMNetworkAdapter | Connect-VMNetworkAdapter -SwitchName "ProductionVSwitch"

In the above command, the -ComputerName parameter and the remote Hyper-V hostname get the VMs and connect them to the ProductionVSwitch VM.

As part of the production change, you must also verify that the VMs successfully connected to the new virtual switch. Use the following PowerShell command to confirm:

Get-VM | Get-VMNetworkAdapter | Export-CSV C:\Temp\VMSwitchConfig.CSV -NoTypeInfo

Use these commands to connect Hyper-V VMs to a Hyper-V virtual switch running on local or remote Hyper-V hosts. With PowerShell commands, the strenuous process of creating a new Hyper-V virtual switch, reconnecting VMs and verifying those connections can be significantly more efficient.

Dig Deeper on IT systems management and monitoring

Software Quality
App Architecture
Cloud Computing
SearchAWS
TheServerSide.com
Data Center
Close