How to add a nic via powershell to an AHV-hosted VM

PowershellAfter getting a question on how to add a network interface card to an existing VM I reverted back to powershell again, this could be useful for PVS scenarios where you want to seperate out network traffic stream (streaming vs generic network traffic) which is an outdated practice but for the sake of the powershell script it was my starting point.

From that older blog, the following interfaces are available:

  • Scripting interfaces (PowerShell)

The following definitions are from the Nutanix Bible as Steve Poitras already explained this:

The REST API exposes every capability and data point of the Prism UI and allows for orchestration or automation tools to easily drive Nutanix action.  This enables tools like Saltstack, Puppet, vRealize Operations, System Center Orchestrator, Ansible, etc. to easily create custom workflows for Nutanix. Also, this means that any third-party developer could create their own custom UI and pull in Nutanix data via REST.

HTML5 GUI (Prism UI)
The HTML5 UI is a key part to Prism to provide a simple, easy to use management interface.  However, another core ability are the APIs which are available for automation.  All functionality exposed through the Prism UI is also exposed through a full set of REST APIs to allow for the ability to programmatically interface with the Nutanix platform.  This allow customers and partners to enable automation, 3rd-party tools, or even create their own UI.

The Acropolis CLI (ACLI) is the CLI for managing the Acropolis portion of the Nutanix product.  These capabilities were enabled in releases after 4.1.2. The Nutanix CLI is the CLI for managing the Nutanix product and is more heterogeneous across hypervisors.

Windows PowerShell is a powerful shell (hence the name ;P) and scripting language built on the .NET framework.  It is a very simple to use language and is built to be intuitive and interactive.

As a reminder, when creating a VM via ACLI all you’d need is a few lines to create a VM, assign a nic to the VM on a specific network and do the same with a disk (create/assign).

Here’s how I managed to do it with Powershell with some error handling on the parameters (i.e. quit the script when the VM/VLAN can’t be found):

Here’s the output when running the script, the first run was succesful because the VM and the vlan could be found. The other 2 runs failed because I made up the vlan name (2nd run) and the VM name (3rd run).

Running the script..
The following two tabs change content below.

Kees Baggerman

Kees Baggerman is a Staff Solutions Architect for End User Computing at Nutanix. Kees has driven numerous Microsoft and Citrix, and RES infrastructures functional/technical designs, migrations, implementations engagements over the years.


  1. Ted says:

    This blog is already dated, but i am still interested if it is also possible to change VMNic of VM to another VLAN. It looks like Nutanix PowerShell only supports adding and removing VMNics but not changing/updating.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.