Using POSH-SSH and PowerCLI to map vNICs to Portgroups without VMware Tools

Had a project recently where we deployed 100’s of VM’s with mulitple NICs without using VMware tool (hand-built kernel without the headers needed).

Upon booting the VM’s we found that the first NIC (VMware side) was consistently eth0, but the others names were not named relative to their order in VMware. The app team was able to log into each VM and provision them as intended according to their process, but the additional interfaces (other than eth0) often had the wrong portgroup and VLAN assigned, making them unable to communicate.

We needed to re-associate 300+ interfaces without being able to pull guest information with VMware Tools. I created a script that used Posh-SSH and PowerCLI to SSH into each VM, pull the interface information, and create an inventory of it’s NICs as well as their MAC and IP Adresses. It then looped through each VM and NIC, matched the MAC address to the correct NIC in VMware, and assigned the correct portgroup based on the IP Address.

I’ve used generic networks and portgroup names for this script, so substitute your own as needed, or adapt as necessary. Hope this helps a few folks.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.