Site icon Digital Thought Disruption

Nutanix VM Inventory Audits with Bash

Introduction

Accurate VM inventory reporting is essential for operations, compliance, and capacity planning. Instead of exporting data manually from Prism, use Bash and Nutanix’s acli to automatically generate inventory reports in CSV format. These reports can feed into asset management systems or compliance checks.


My Personal Repository on GitHub

Nutanix Repository on GitHub


Diagram: VM Audit Script Flow


What We’ll Extract


Bash Script: nutanix_vm_inventory.sh

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

output="vm_inventory_$(date +%F).csv"
echo "VM Name,vCPUs,MemoryMB,PowerState,Network,IP" > "$output"

vms=$(acli vm.list | awk 'NR>2 {print $1}')
for vm in $vms; do
info=$(acli vm.get "$vm")
cpu=$(echo "$info" | awk '/num_vcpus/ {print $2}')
mem=$(echo "$info" | awk '/memory_mb/ {print $2}')
power=$(echo "$info" | awk '/power_state/ {print $2}')
net=$(echo "$info" | awk '/network/ {print $2}')
ip=$(echo "$info" | grep ip_address | awk '{print $3}')

echo "$vm,$cpu,$mem,$power,$net,$ip" >> "$output"
done

Output Example

VM Name,vCPUs,MemoryMB,PowerState,Network,IP
web01,2,4096,on,VLAN10,10.1.10.21
db01,4,8192,off,VLAN20,10.1.20.15

Optional Enhancements

0 6 * * * /usr/local/bin/nutanix_vm_inventory.sh

Summary

With a few lines of Bash and acli, you can export VM inventories on-demand or on schedule. This supports operational readiness, audit compliance, and visibility for Nutanix-based environments.

External Documentation:

Exit mobile version