Deploy Hyper-V VM Switches and vNIC consistency with PowerShell

Posted by Romain Serre on February 26, 2016
Share on Facebook0Share on Google+0Share on LinkedIn0Share on Reddit0Tweet about this on Twitter0
4.7/5 (10)

When a large Hyper-V infrastructure is deployed, often Virtual Machine Manager (VMM) is installed. It enables to deploy logical switches which are mainly VM Switches and virtual network adapters for Live-Migration, Backup, heartbeat, storage or management purposes. However small or medium business doesn’t necessarily implement VMM because it is expensive or not well-known. Even if you don’t use VMM, you can deploy consistency VM Switches on several Hyper-V by using PowerShell. This topic aims to show you how to deploy VM Switches and virtual network adapters by using PowerShell. In this way you will be able to make a standard script to configure your Hyper-V hosts.

Manage a teaming

The teaming may be necessary if you want a highly available environment.

Get Physical NIC information

Before creating any VM Switches, you need to obtain the physical network adapters information. For that, you can use the PowerShell cmdlet called Get-NetAdapter.

Now that I have details about my physical network adapters, I will make a filter to show only the network adapters I want to add to a teaming and select relevant information.


Create the teaming

To create the teaming, I use the command New-NetLbfoTeam as below:


4If I open the Server Manager, you can see the teaming well created:


Add / Remove NIC from teaming

To add a NIC to the teaming, just use Add-NetLbfoTeamMember cmdlet as below. In the below example I add the STO01 network adapter to the teaming that I have just created.



To remove the NIC from the teaming just use Remove-NetLbfoTeamMember cmdlet:


Manage the VMSwitch

Create the VMSwitch

Now that your teaming is created, you can create the VMSwitch. The teaming is not a prerequisite to deploy a VMSwitch. But in production, usually a teaming is created to avoid single point of failure. To create a VM Switch, you can use the New-VMSwitch command. With this command you can create External, Internal or Private switch. In the below command, I create an external VMSwitch with the teaming previously created:


If you want to create a private or an internal VMSwitch, specify the -SwitchType Internal/Private argument in the New-VMSwitch command. You can also enable SR-IOV by specifying -EnableIov.


Modify VMSwitch configuration

You can change some settings in the VMSwitch configuration with the command Set-VMSwitch. This command allows you to change the switch type, the connected network adapter and so on.


Manage virtual Network Adapters

Add a virtual NICs

Now that the VMSwitch is created, you can create vNICs connected to this VMSwitch.  For example, when you create a VMSwitch for Hyper-V management usage, usually you need to create vNICs for Live-Migration, Management, cluster heartbeat and so on. To create a vNIC, you can use the command Add-VMNetworkAdapter as below:

12When the vNIC is created I can have information about it with PowerShell by using the Get-VMNetworkAdapter command (don’t forget -ManagementOS for parent partition vNIC):



Change the VLAN configuration

When you implement network convergence, you have to configure the VLAN for each vNIC that you have added to a VMSwitch. To get the VLAN configuration of each vNIC that you have created, you can use Get-NetworkAdapterVLAN as below:


To change the VLAN configuration, you can use Set-VMNetworkAdapterVLAN cmdlet:


Now my LiveMigration vNIC is set to tag packet with VLAN ID 200. You can also set a vNIC to trunk mode by specifying the native VLAN and a list of allowed VLAN.

Example: Script to configure management networks

The below script create a teaming, a VMSwitch, vNICs and set the VLAN. It can be useful to deploy several Hyper-V and make a consistent configuration.


You can add other settings to this script as VMQueue or RSS configuration. By using a script to configure all your Hyper-V environment, you are sure that all configuration is the same.


Related materials:

Views All Time
Views Today

Please rate this

To download the software products, please, make your choice below. An installer link and a license key will be sent to the e-mail address you’ve specified. If you consider StarWind Virtual SAN but are uncertain of the version, please check the following document Free vs. Paid. The recent build of Release Notes. A totally unrestricted NFR (Not For Resale) version of StarWind Virtual SAN is available for certain use cases. Learn more details here.

Return to all posts

Deploy MSI package to group of computers in your domain
Cisco coming up with a hyper-converged infrastructure solution
The following two tabs change content below.
Romain Serre
Romain Serre
Senior consultant at Exakis
Romain Serre works in Lyon as a Senior Consultant. He is focused on Microsoft Technology, especially on Hyper-V, System Center, Storage, networking and Cloud OS technology as Microsoft Azure or Azure Stack. He is a MVP and he is certified Microsoft Certified Solution Expert (MCSE Server Infrastructure & Private Cloud), on Hyper-V and on Microsoft Azure (Implementing a Microsoft Azure Solution).