Changing vNIC Port Group Assignment in VMware with PowerShell
Published on 5 Jan 2009 · Filed in Explanation · 142 words (estimated 1 minutes to read)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!