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 😀

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s