Using Windows PowerShell to change the VM-Switch assigned to Virtual Machine’s (Windows 2012, Windows 8)

Recently I’ve been trying to do some lab setup for a demonstration. One of the constant changes I do is creating and deleting VM’s in my laptop and creating various Network switches for VM’s. Now assigning a VM-Switch to a virtual machine can be easy task by using GUI but it can be painful it you’ve to go through each VM’s settings page and selecting the correct VM-Switch. You’ll get the idea if you’ve been managing more than 10-15 VM’s in your lab setup like I do Smile

image

(My HYPER-V console in the laptop)

image

(VM-Switch I’ve created for various labs)

 

Now using PowerShell we can assign VM-Switch to selected number of VM’s in one parameter or to entire VM’s in my laptop in one go. Now this reminds me the famous quote in Spiderman movie “Great power comes with great responsibilities” Smile Anyway we’ll use the power carefully in the PowerShell.

Now assuming I want to change only selected VM’s VM-Switch to “PrivateNetwork” I can run the PS command as follows,

Connect-VMNetworkAdapter -VMName Demo-WIN2008R2-DC,Demo-WIN2008R2-SRV1,DEMO-WIN2008R2-SRV2 –Switch PrivateNetwork

image

Assuming I want to change all VM’s VM-Switch name to “VMSW01” all I have to do is type the following command,

Connect-VMNetworkAdapter –VMName * –SwitchName VMSW01 

Note: I found out in your VM-Switch naming convention if you keep spaces and use that VMM-Switch name in PowerShell it won’t work. This is something I yet to find out.

Advertisements

One thought on “Using Windows PowerShell to change the VM-Switch assigned to Virtual Machine’s (Windows 2012, Windows 8)

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