Change the VMSwitch of all VMs on a host.

I had a requirement today to change the VMSwitch associated to all the VMs on my Hyper-v host. Obviously if you had time on your hands an really wanted to you can go through and change each one individually with the mouse but far more efficient would be to use PowerShell!

I started off with a:

Get-VM | Connect-VirtualNetworkAdapter –SwitchName “MySwitchName”

This won’t work though as you can see here the -VMName does not accept a piped input.

All you need to do though is just use a wildcard (*) for the VMName instead:

Connect-VirtualNetworkAdapter –SwitchName “MySwitchName” -VMName *

And instantly all your VMs will be on the new adaptor.

The Power of PowerShell 😀