VMware

PowerCLI change network label for all VMs in a folder

Let's take a look at PowerCLI change network label for all VMs in a folder topic and see how quickly we can change the port group membership of a VM.

Just a quick blurb and a useful one liner used to change all the Network labels for all virtual machines that existed in a vCenter folder. ย I had a situation in a lab where I imported numerous server VMs from a production network that would be used for development/testing. ย In vCenter these were brought in just with the default first network in the list. ย This process is cumbersome to do if you are simply manually editing the properties of each VM and changing the network label/port group. ย In steps PowerCLI. ย Let’s see how to use PowerCLI change network label for all VMs in a folder.

PowerCLI change network label for all VMs in a folder

To do this we want to first connect into vCenter. ย If you connect to an individual host within your environment, using the connect-viserver commandlet, you will not be able to target “folders” in your -location parameter as only in vCenter do you have visibility into folders. ย So first let’s connect to vCenter:

connect-viserver yourvcenter.somedomain.com

After we have connected to vCenter, let’s use the one liner we mentioned about to pull out the networkname of the VMs in a particular folder and then set the network adapter network name to a networkname of our choosing.

get-vm -location "MYFOLDER" | get-networkadapter | where {$_.NetworkName -eq "Some Network"} | Set-NetworkAdapter -NetworkName "AnotherNetwork" -confirm:$true

As you can see above, it reads the VMs in the folder location, gets the current network adapter properties – in particular the networkname and then sets that networkname to the network that we want it to be. ย I placed a -confirm:$true on the end just to make sure things were setting as expected.

networkname01

You can easily take the confirmation off the PowerCLI one liner and it will blast through the VMs in the blink of an eye.

Final Thoughts

There are so many PowerCLI network one liners and other scripts out there that make your life as a virtualization admin so much easier. ย Mundane tasks such as used toย change network label for all VMs in a folder can easily be done with PowerCLI.

Subscribe to VirtualizationHowto via Email ๐Ÿ””

Enter your email address to subscribe to this blog and receive notifications of new posts by email.



Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com, and a 7-time VMware vExpert, with over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, He has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family. Also, he goes through the effort of testing and troubleshooting issues, so you don't have to.

Related Articles

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.