Home » Nutanix » Capturing Nutanix Infra details using PowerShell

In this post, I will use Nutanix REST API and PowerShell to capture the details for inventory creation.

Prism is the management component of Nutanix distributed architecture. Prism service runs on every Nutanix Controller VMs (CVM) that each Nutanix Node needs to host. Among the CVMs in a cluster, one is elected as a leader to serve the HTTP based management requests. This component is called the Prism Element (PE) and is responsible for cluster-wide management. A multi-cluster environment can host the optional Prism Central (PC) to management the clusters from a single interface.

This picture from Nutanix bible https://nutanixbible.com/#anchor-book-of-prism-architecture gives the overview of Prism Element and Central. While each node hosts the CVM and hence the prism element, prism central is a virtual appliance that needs to be host separately as a VM.

While providing an HTML5 UI for browser-based management, Prism also provides the functionalities through REST API for the customized interface, automation, and orchestration creation purpose. PRISM v3 is available with Prism Central and v2.0 with a prism element. These are well documented at the Nutanix developer portal https://www.nutanix.dev/api-reference/. In addition, the REST API explore within the prism element gives a quick overview of data points and methods available with them. In this post, I will be using v2.0 API.

# Define the bellow three variables 
$NutanixclusterName = "Hostname or FQDN of Prism Element"
$reportFolder =  "Forlder to create the Report"
$NXCredential = "username:password"

# Bellow requried if using self signed or untrusted certificate on Prism Element
dd-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

#Creating authorization Header for REST API call
$Header = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($NXCredential))}
#Define the Report file to save the inventory  data
$NtnxPNodeReportName = "NX_Node-" + (Get-Date -Format dd-MMM-yyyy) + ".csv"
$NtnxPNodeReportFile = Join-Path $reportFolder $NtnxPNodeReportName

# Let's get Node details of the cluster 
$NtnxRestData=Invoke-RestMethod -Method Get -Uri "https://$($NutanixclusterName):9440/api/nutanix/v2.0/hosts/" -Headers $Header

for ($i = 0; $i -lt $NtnxRestData.metadata.end_index; $i++) {
# NX cluster and Hostname, followed by IP addreess of NX, IPMI and hypervisor
# Node and Block serial Number, Block Model, CPU, CPU Cores and number of CPUs, memeory 
# Hypervisor, its version, Number of VMs. Model and version detail of BIOS, BMC, HBA
# Disk model, SN and FW version. Upto 6 disks. Increase or Descrese as requried.
# Storage capacity, physical and logical usage  of the Node

$Report1 = ""|select NxCluster,NXHost,NXIP,OOBIP,HPVIP,NSN,BSN,Bmodel,CPU,Cores,Sockets,RAMGB,HPV,HPVVer,VMs, `
BIOSm,BIOSv,BMCm,BMCv,HBA1m,HBA1v,HBA2m,HBA2v,Disk1m,Disk1sn,Disk1fw,Disk2m,Disk2sn,Disk2fw, `
Disk3m,Disk3sn,Disk3fw,Disk4m,Disk4sn,Disk4fw,Disk5m,Disk5sn,Disk5fw,Disk6m,Disk6sn,Disk6fw, `

$Report1.NxCluster = $ntnxclus
$Report1.NXHost = $NtnxRestData.entities[$i].name
$Report1.NXIP = $NtnxRestData.entities[$i].service_vmexternal_ip
$Report1.OOBIP = $NtnxRestData.entities[$i].ipmi_address
$Report1.HPVIP = $NtnxRestData.entities[$i].hypervisor_address
$Report1.NSN = $NtnxRestData.entities[$i].serial
$Report1.BSN = $NtnxRestData.entities[$i].block_serial
$Report1.Bmodel = $NtnxRestData.entities[$i].block_model_name
$Report1.CPU = $NtnxRestData.entities[$i].cpu_model.Split(" ")[3,4,6] -join " "
$Report1.Cores = $NtnxRestData.entities[$i].num_cpu_cores
$Report1.Sockets = $NtnxRestData.entities[$i].num_cpu_sockets
$Report1.RAMGB = ($NtnxRestData.entities[$i].memory_capacity_in_bytes / 1GB).ToString("#")
$Report1.HPV = $NtnxRestData.entities[$i].hypervisor_type
$Report1.HPVVer = $NtnxRestData.entities[$i].hypervisor_full_name
$Report1.VMs = $NtnxRestData.entities[$i].num_vms
$Report1.BIOSm = $NtnxRestData.entities[$i].bios_model
$Report1.BIOSv = $NtnxRestData.entities[$i].bios_version
$Report1.BMCm = $NtnxRestData.entities[$i].bmc_model
$Report1.BMCv = $NtnxRestData.entities[$i].bmc_version
$Report1.HBA1m = $NtnxRestData.entities[$i].hba_firmwares_list[0].hba_model
$Report1.HBA1v = $NtnxRestData.entities[$i].hba_firmwares_list[0].hba_version
$Report1.HBA2m = $NtnxRestData.entities[$i].hba_firmwares_list[1].hba_model
$Report1.HBA2v = $NtnxRestData.entities[$i].hba_firmwares_list[1].hba_version
1..6 |% {
    $disknumber = $_ 
    $diskmodel = "disk"+$disknumber+"m";$disksn = "disk"+$disknumber+"sn";$diskfw = "disk"+$disknumber+"fw"
    $Report1.$diskmodel = $NtnxRestData.entities[$i].disk_hardware_configs.$disknumber.model
    $Report1.$disksn = $NtnxRestData.entities[$i].disk_hardware_configs.$disknumber.serial_number
    $Report1.$diskfw = $NtnxRestData.entities[$i].disk_hardware_configs.$disknumber.current_firmware_version
$Report1.StorageCapGB = ($NtnxRestData.entities[$i].usage_stats.'storage.capacity_bytes' / 1GB).ToString("#")
$Report1.StorageUseGB = ($NtnxRestData.entities[$i].usage_stats.'storage.usage_bytes' / 1GB).ToString("#")
$Report1.StorageUseLogical = ($NtnxRestData.entities[$i].usage_stats.'storage.logical_usage_bytes' / 1GB).ToString("#")
$Report1.StorageFree = ($NtnxRestData.entities[$i].usage_stats.'storage.free_bytes' / 1GB).ToString("#")
$Report1.StorageFree = ($NtnxRestData.entities[$i].usage_stats.'storage.free_bytes' / 1GB).ToString("#")
$Report1.StorageSSDCap = ($NtnxRestData.entities[$i].usage_stats.'storage_tier.ssd.capacity_bytes' / 1GB).ToString("#")
$Report1.StorageHDDCap = ($NtnxRestData.entities[$i].usage_stats.'storage_tier.das-sata.capacity_bytes' / 1GB).ToString("#")

# Lets Save the data to the report File 
$Report1 | Export-Csv -Append $NtnxNodeReportFile


Next post will be to retrieve the same for multiple clusters through prism central

Leave a Reply

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