PowerCLI

VMware PowerCLI quickly add multiple VM vmnics

PowerCLI is a powerful tool that can be utilized to quickly perform tasks in a VMware environment. One of the overly painful tasks that you encounter when configuring or reconfiguring a VM is adding vmnics. Especially is this painful if you need to add multiple nics perhaps to many different VMs or specific ones. With VMware PowerCLI quickly add multiple VM vmnics is easily performed.

VMware PowerCLI quickly add multiple VM vmnics

The problem with the GUI interfaces is that you can’t really add multiple nics without a lot of clicking and tedious configuration. Multiple nic addition is only available in the fat vSphere client and not the Web client. This is limited to (4) vmnics on a new VM.

pclimultvmnic02

Additionally, when you bring up a new VM in the Web client, you are taken to a screen where you can add multiple vmnics, however, it can only be done one at a time (painful).

pclimultvmnic01

PowerCLI

In steps PowerCLI. With PowerCLI we can automate the addition of vmnics to any of our virtual machines. The commandlet we use is the new-networkadapter commandlet. We can specify several parameters with this commandlet including the VM we want to add to, the networkname or port group to attach the network adapter to, the type (vmxnet3, etc) and we can specify we want the network adapter to startconnected.

new-networkadapter -vm <vmname> -NetworkName "<Port group name>" -Type "VMXNET3" -startconnected

With the above one liner, we can add vmnics to the VM that is specified by the -vm parameter with the specific parameters we described above.

Multiple vmnics

If we want to add a specific number of network adapters to a certain VM, we can do that with a foreach loop with a count statement. The below will add (4) new network adapters to a specific VM identified with the -vm parameter.

#Multiple vmnics on a specified VM

foreach ($i in 1..4){
    new-networkadapter -vm <vmname> -NetworkName "<Port group name>" -Type "VMXNET3" -startconnected
    }
    }

Multiple vmnics, Multiple VMs

What though if we want to add (4) new vmnics to a list of VMs? We can nest our foreach loop inside another foreach loop and use a variable to read in the contents of a VM list.

#Multiple vmnics on multiple VMs

$vms=get-content c:vms.txt

foreach ($vm in $vms){

foreach ($i in 1..4){
    new-networkadapter -vm $vm -NetworkName "Port group name" -Type "VMXNET3" -startconnected
    }
    }

Thoughts

With VMware PowerCLI quickly add multiple VM vmnics is easily accomplished either on one specific VM or reading in a list of VMs we want to modify. It is a great tool for automation as well as quickly provisioning and making changes that otherwise would be very tedious in the vSphere Web client. Long live PowerCLI!