API, English, Technology

REST API / PowerShell Mass VM Power Control

A customer is using the power of Prism to manage his entire infrastructure. Although the Prism UI controls grant all the power you need. The true power of Nutanix lies in the REST API capabilites.

In this simple example, the API is used to power controll a larger set of VMs.

The script has several parameters for exectution:

It uses a PSM1 module for functions and a ps1 file for execution.
You can launch the script using the PS1 file. Edit default params where needed. Please make sure you configure the install directory.

Note, this script has been built for AHV. Should work on ESXi but not tested.

About the parameters:
Target “PC” will use bulk API commands, Target PE will loop through the Array of objects.
Use Mode “Scan” to test your filters.
Only use force if you know the filter is working.
Filter is a powershell based regex filter, see the base example.
InvertFilter will negate the matcher.
Nr Loops can generally stay the same, logic will exit if task is completed.
Desired state, On, off, acpi_shutdown.

Scan Mode:

Target PC, state already set:

Target PC, force, acpi_shutdown

Code is here: