Batch Power Control of Nutanix VMs via CLI

Introduction

Powering on or shutting down multiple VMs through the Prism interface can be tedious. With Bash and Nutanix’s acli, you can automate batch VM power operations, whether for scheduled maintenance, environment resets, or DR runbooks. This article shows how to control power states for multiple VMs based on name patterns, tags, or input lists.


My Personal Repository on GitHub

Nutanix Repository on GitHub


Diagram: VM Power Script Architecture


Sample Input File: vms.txt

web01
web02
db01
db02

Script: Power Off All VMs from List

#!/usr/bin/env bash
set -euo pipefail

input="vms.txt"
log="/var/log/nutanix_power_batch.log"

while IFS= read -r vm; do
echo "[$(date)] Shutting down $vm" | tee -a "$log"
acli vm.off "$vm"
done < "$input"

To Power On Instead

acli vm.on "$vm"

Replace in the loop to power on instead of off.


Optional: Check Power State Before Action

status=$(acli vm.get "$vm" | grep -i "power state" | awk '{print $3}')
if [[ "$status" != "off" ]]; then
acli vm.off "$vm"
fi

Add a Delay Between Actions

For graceful cluster performance:

sleep 10

Insert between commands to stagger actions.


Schedule with Cron

0 20 * * 5 /usr/local/bin/nutanix_power_down.sh

This example powers down VMs every Friday at 8:00 PM.


Summary

Bash and acli make it easy to automate VM power control in AHV clusters. Whether you’re preparing for maintenance or running operational workflows, batch control saves time and reduces human error.

External Documentation:

Leave a Reply

Discover more from Digital Thought Disruption

Subscribe now to keep reading and get access to the full archive.

Continue reading