PowerCLI – Nexus1000v and VMXNET3

Today’s post is brought to us by Chris, a member of the VMware community who wields some powerful Louisianan VooDoo magic (and PowerCLI). Chris uses this to show us how to take a csv file in, and use it to attach a VM to a dVS switch as well as adding the VMXNET3 nic to the VM. Getting right on with it:

Story:

Had to bulk create a bunch of VMs. The new server standard has each production server on 2 networks, the normal production network, and an auxiliary network (for backups, updates, management, etc). The issue I ran into was that our switches were created in vSphere as virtual distributed switches (using the Cisco Nexus 1000v). The standard new-vm script wouldn’t allow you to connect the network adapter to that switch, unfortunately. Also, we preferred to use VMXNET3 NICs as opposed to the default e1000, another thing that new-vm doesn’t allow. So I wrote the following script in PowerCLI that does the following:

  • Reads in a CSV file (fields: Name,Description,OS,Disk,Memory)
  • Connects to the vSphere server (you specify the server and cluster to add VMs to).
  • Creates a VM in the specified folder on the ESX host with the least memory utilization and the datastore with the most free space and having at least 30gb free space
  • Removes the default e1000 NIC
  • Adds 2 VMXNET3 NICs on temporary networks (cannot add directly to vDS)
  • Connects the 2 VMXNET3 NICs to the vDS
  • Powers on VM

Tried to generalize code as much as possible, works here, but this was a new rollout so there may be differences in how other people have it.

Script:

Ending

One thought on “PowerCLI – Nexus1000v and VMXNET3”

Comments are closed.