VMware PowerCLI

VMware PowerCLI quickly add multiple VM vmnics

Modifying network settings can be very tedious through the vSphere client or Web client. With VMware PowerCLI quickly add multiple VM vmnics is easy.

Highlights

  • 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.
  • 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.
  • 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).

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!

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 has 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.