Some Nutanix AHV PowerShell Commands I found useful 2

Recently I needed to script some actions for a VM on Nutanix AHV.

I wanted to share with you some of the commands I found and used.

I created a small function (Wait-NTNXTask) that verifies the task and waits until the task is finished.

Pleas note that this is optional and not required to run the commands specified in this blog.

To start with Nutanix AHV and PowerShell you need to install the PowerShell Cmdlets. You can find the snap-ins when you click on your name and select “Download Cmdlets Installer”

Add the snap-ins to your script or session:

If you want to view all the commands associated to “NutanixCmdletsPSSnapin” run the following command:

View the Cmdlet (version) information:

Before we can make changes we need to create a connection:

NOTE: If you receive the following error “The remote server returned an error: (401) Unauthorized.” You will need to reconnect. May be that the connection has timed out.

Get the VM so we can use the ID’s:

Create a new snapshot for a given VM:

Retrieve all the available snapshots for a given VM:

Get a particular snapshot for a given VM, if there are multiple snapshots with the same name all will be returned. In this example we will retrieve the last available snapshot:

Revert back to a snapshot for a given VM:

Removing one or more snapshots for a given VM:

You can also add or remove disk to a given VM. Below is a working example how to remove disks and add them again with the same parameters:

You can also manipulate the CD-ROM drive attached to your VM to mount or un-mount an ISO file.

First we need to retrieve the details for the CD-ROM drive attached to a given VM:

It can be that you have multiple CD-ROM drives attached to a given VM. Make sure you have selected only one.

In the next example we will check if there are multiple drives, if so we’ll select the first one. (You can make your selection as you see fit)

To check if a CD-ROM drive already contains an image or is empty:

To list and get the names of all the available ISO files uploaded you can run the following command

To mount an ISO to a (existing) CD-ROM drive.

To un-mount an ISO attached the CD-ROM drive:

If you want NIC details, for example if you want to know the MAC Address of a given VM:

And finally how to turn on or off a given VM.

Power on a given VM:

Power off a given VM:

Specifying the transition, for example to nicely shutdown a given VM:

The following Transitions can be specified:

  • OFF
  • ON

Recently Kees Baggerman informed me that Nutanix was working on some new PowerShell Cmdlets. Unfortunately I didn’t had the time to look at them.

Hope this will help you.


Leave a comment

Your email address will not be published. Required fields are marked *

2 thoughts on “Some Nutanix AHV PowerShell Commands I found useful