Tag: VMSwitch

Hyper-V VM Switch

Change Hyper-V VM Switch of Virtual Machines using PowerShell

This is one of the first post of a short blog series with some simple PowerShell scripts and oneliners for Hyper-V. One this is how you can connect a Virtual Network Adapter of a Hyper-V Virtual Machine to another Virtual Switch.

This is very simple, with this command you can see all the Network Adapters of the Virtual Machine and to which Switch they are connected:

Get-VM "VM01" | Get-VMNetworkAdapter

With this command you can connect it to another Switch:

Get-VM "VM01" | Get-VMNetworkAdapter | Connect-VMNetworkAdapter -SwitchName "NewSwitch"

Now of course you can also do this for all Virtual Machines running on a Hyper-V host:

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

Create NAT Virtual Switch on Hyper-V

Hyper-V Virtual Switch using NAT Configuration


This blog post is blog post is for older Windows 10 builds, for newer Windows 10 (1607) and Windows Server 2016 builds please follow this blog post:

Set up a Hyper-V Virtual Switch using a NAT Network

In the latest Windows 10 build 10586 (Threshold 2) and Windows Server 2016 Technical Preview 4, Microsoft included a great new feature which is NAT mode for the Hyper-V Virtual Switch. This was mostly build for Windows Containers scenarios, but also has great value for Client Hyper-V. As of today Hyper-V had 3 different VMSwitch types called, Internal, Private and External. With the latest releases of the Windows 10 and Windows Server 2016 Technical Preview 4, Microsoft included a new VM Switch Type called NAT, which allows Virtual Machines to have a Internal Network and connect to the external world and internet using NAT. This feature right now is not included in the UI but you can use PowerShell to create the NAT Virtual Switch.

Create a new Virtual Switch using NAT:

Create NAT Virtual Switch on Hyper-V

New-VMSwitch -Name "NATSwitch" -SwitchType NAT -NATSubnetAddress

Setup the NAT configuration:

New-NetNat -Name VMSwitchNat -InternalIPInterfaceAddressPrefix ""

This will create a new VM Network Adapter on the host using the IP Address. You can now use the NATSwitch to connect Virtual Machines. You can now set IP Addresses inside Virtual Machines to the subnet and add as the default gateway and you are good to go.

Hyper-V Virtual Switch NAT Configuration

Create a new NAT forwarding

To forward specific ports from the Host to the guest VMs you can use the following commands.

This example creates a mapping between port 80 of the host to port 80 of a Virtual Machine with an IP address of

Add-NetNatStaticMapping -NatName "VMSwitchNat" -Protocol TCP -ExternalIPAddress -InternalIPAddress -InternalPort 80 -ExternalPort 80

This example creates a mapping between port 82 of the Virtual Machine host to port 80 of a Virtual Machine with an IP address of

Add-NetNatStaticMapping -NatName "VMSwitchNat" -Protocol TCP -ExternalIPAddress -InternalIPAddress -InternalPort 80 -ExternalPort 82

This also works with Windows and Hyper-V Containers.

Update – 4/27/2016 #1

As many of the people mentioned, the option of the SwitchType NAT is gone in the latest Windows Insider Preview builds of Windows 10. If you have created a NAT Switch in Windows 10 before the upgrade to a Windows 10 insider build, the switch is still working. There is no comment at the moment from Microsoft on this. But Microsoft announced Hyper-V Container support for Windows 10, and since the NAT Switch makes totally sense when you are using containers, I guess the SwitchType for NAT will be coming back.

Update – 4/27/2016 #2

With the latest Windows 10 Insider Build 14332, I saw some Container Network PowerShell cmdlets, which maybe will replace the Hyper-V Switch NAT cmdlet options for the future. But this is just guessing.

Container Network PowerShell

Update – 5/3/2016

Here is a updated version how you can configure the Hyper-V NAT Switch in newer Windows 10 and Windows Server 2016 builds.

Have fun and enjoy! Thanks to Ben Armstrong (Microsoft VirtualPCGuy) for the info.