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 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 Microsoft Hyper-V management
Related Q&A from Nirmal Sharma
Download and install Microsoft Virtual Machine Converter to gain access to several PowerShell commands that enable VMware VMDK to Hyper-V VHDX ... Continue Reading
Take advantage of PowerShell commands to clear ISO files from your VMs before booting and ensure their configuration is set to boot from the virtual ... Continue Reading
To see virtual processors configured for VMs on the local host, execute a simple PowerShell command. For vCPUs configured for VMs on remote servers, ... Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.