, , , , ,

Change Hyper-V VM Switch of Virtual Machines using PowerShell

Hyper-V VM Switch

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

2 responses

  1. Dave Avatar

    Just wanted to say thanks Thomas! Exactly what I needed to point me in the right direction. In my case, I wanted to apply a switch to all of my VMs adapters (not just one) so I just left out the VM name.

    1. Thomas Maurer Avatar

      Thank you Dave, great that this blog helped you!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.