Create a Virtual Switch in Hyper-V using Powershell

Introduction

A virtual switch allows virtual machines created on Hyper-V hosts to communicate with other computers. You can create a virtual switch when you first install the Hyper-V role on Windows Server. We are going to use Powershell to create the virtual switch in this case. To learn more about virtual switches, see Hyper-V Virtual Switch

Prerequisites

Ensure you have one of the following : Windows 10, Windows Server 2016, Microsoft Hyper-V Server 2016, Windows Server 2019, Microsoft Hyper-V Server 2019

Instruction

  • Firstly open Powershell from the start menu (ensure you run as administrator) and type the following to find the available network adapters.  The results are shown in the screenshot below
Get-NetAdapter 
  • Now create the virtual switch based on the adaptor you have chosen to use, in this case for me it was the Intel (R) Ethernet Connection (2) I218-LM (Wired) which i wanted to use as an external network.  For this the command would be as shown below.  You can make the name anything you want but the NetAdapterName must be from one of the results produced from the Get-NetAdapter command.  Once the vSwitch has been created your window will look like the one below
New-VMSwitch -name BlackwaterConfig -NetAdapterName Ethernet -AllowManagementOS $true
  • If you wanted to create a switch for an internal network the command would be
New-VMSwitch -name BlackwaterConfig -SwitchType Internal 
  • When you open Hyper-V Manager now in GUI mode and go to the Virtual Switch Manager you will see your newly created switch which in my case is called BlackWaterConfig