Experienced PowerShell users won’t find this post very helpful, but less experienced PowerShell users—or even PowerShell newbies such as me—may find this handy. Today I had a need to change the port group assignment on the vNICs for a bunch of guest VMs in the lab. Rather than manually click through all these VMs just to change the port group, I decided to give PowerShell a try.
Thanks to this post by Cody Bunch and this Twitter response by Hal Rottenberg, I cobbled together this PowerShell command:
get-datacenter "Name" | get-vm | get-networkadapter | where-object { $_.networkname -like "OldPortGroup" } | set-networkadapter -networkname "NewPortGroup" -Confirm:$false
It worked like a champ! Obviously, you could limit the scope of this command by filtering the VMs that are returned with a wildcard pattern on the Get-VM command.
Thanks to Cody and Hal for their assistance!
Tags: ESX, Networking, Virtualization, VLAN, VMware
-
Scott;
Could you provide a screen shot of what your port group assignment looked like before and after running this command? I’d like to “see” what it does? Thanks. Don Whittaker




2 comments
Comments feed for this article
Trackback link: http://blog.scottlowe.org/2009/01/05/changing-vnic-port-group-assignment-in-vmware-with-powershell/trackback/