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

(My HYPER-V console in the laptop)

(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” 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,