Last week Magnus Andersson posted a Nutanix AHV VM Reporting script which leverages the internal commandline options to export some basic VM configuration to an excel file. In the same week our team got a question about how to do this based on powershell.
When I combined those two I took on the challenge and wrote a few lines of powershell to collect similar information and drop it into CSV.
The script will collect the following information:
- VM Name
- Contrainer (which datastore the primary boot disk is stored on)
- Protection Domains
- Host Placement
- Power State
- The number of network adapters
- IP addresses
- The number of vCPUs
- The amount of vRAM assigned to the VM (GB)
- Disk count
- Provisioned space (GB)
- Used space (GB)
Running the script is pretty straightforward, make sure you have the powershell cmdlets installed (Go to Prism, select Admin and click on “Download Cmdlets installer). This script was tested with the cmdlets in AOS5. Once the cmdlets are installed you can run the following command line:
1 |
.\Nutanix_VM_Inventory_v1.ps1 -nxIP "99.99.99.99.99" -nxUser "admin" |
This will provide you with a CSV file stored on your desktop called “NutanixVMInventory.csv”:
The script itself:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
<# .SYNOPSIS Creates a complete inventory of a Nutanix environment. .DESCRIPTION Creates a complete inventory of a Nutanix Cluster configuration using CSV and PowerShell. .PARAMETER nxIP IP address of the Nutanix node you're making a connection too. .PARAMETER nxUser Username for the connection to the Nutanix node .PARAMETER nxPassword Password for the connection to the Nutanix node .EXAMPLE PS C:\PSScript > .\nutanix_inventory.ps1 -nxIP "99.99.99.99.99" -nxUser "admin" .INPUTS None. You cannot pipe objects to this script. .OUTPUTS No objects are output from this script. This script creates a CSV file. .NOTES NAME: Nutanix_Inventory_Script_v1.ps1 VERSION: 1.0 AUTHOR: Kees Baggerman with help from Andrew Morgan LASTEDIT: February 2017 #> # Setting parameters for the connection [CmdletBinding(SupportsShouldProcess = $False, ConfirmImpact = "None") ] Param( # Nutanix cluster IP address [Parameter(Mandatory = $true)] [Alias('IP')] [string] $nxIP, # Nutanix cluster username [Parameter(Mandatory = $true)] [Alias('User')] [string] $nxUser, # Nutanix cluster password [Parameter(Mandatory = $true)] [Alias('Password')] [Security.SecureString] $nxPassword ) # Adding PS cmdlets $loadedsnapins=(Get-PSSnapin -Registered | select name).name if(!($loadedsnapins.Contains("NutanixCmdletsPSSnapin"))){ Add-PSSnapin -Name NutanixCmdletsPSSnapin } # Connecting to the Nutanix Cluster $nxServerObj = Connect-NTNXCluster -Server $nxIP -UserName $nxUser -Password $nxPassword -AcceptInvalidSSLCerts # Fetching data and putting into CSV $vms = @(get-ntnxvm) $FullReport=@() foreach ($vm in $vms){ $usedspace=0 if(!($vm.nutanixvirtualdiskuuids.count -le 0)){ foreach($UUID in $VM.nutanixVirtualDiskUuids){ $usedspace+=(Get-NTNXVirtualDiskStat -Id $UUID -Metrics controller_user_bytes).values[0] } } if ($usedspace -gt 0){ $usedspace=[math]::round($usedspace /1gb,0) } $container= "NA" if(!($vm.vdiskFilePaths.count -le 0)){ $container = $vm.vdiskFilePaths[0].split('/')[1] } $props=[ordered]@{ "VM Name" = $vm.vmName "Container" = $container "Protection Domain" = $vm.protectionDomainName "Host Placement" = $vm.hostName "Power State" = $vm.powerstate "Network adapters" = $vm.numNetworkAdapters "IP Address(es)" = $vm.ipAddresses -join "," "vCPUs" = $vm.numVCpus "vRAM (GB)" = [math]::round($vm.memoryCapacityInBytes / 1GB,0) "Disk Count" = $vm.nutanixVirtualDiskUuids.count "Provisioned Space (GB)" = [math]::round($vm.diskCapacityInBytes / 1GB,0) "Used Space (GB)" = $usedspace } #End properties $Reportobject= New-Object PSObject -Property $props $fullreport+=$Reportobject } $fullreport | Export-Csv -Path ~\Desktop\NutanixVMInventory.csv -NoTypeInformation -UseCulture # Disconnecting from the Nutanix Cluster Disconnect-NTNXCluster -Servers * |
A thank you goes out to Andrew Morgan for being ever so patient and answering my questions!
Kees Baggerman
Latest posts by Kees Baggerman (see all)
- Nutanix AHV and Citrix MCS: Adding a persistent disk via Powershell – v2 - November 19, 2019
- Recovering a Protection Domain snapshot to a VM - September 13, 2019
- Checking power settings on VMs using powershell - September 11, 2019
- Updated: VM Reporting Script for Nutanix with Powershell - July 3, 2019
- Updated (again!): VM Reporting Script for Nutanix AHV/vSphere with Powershell - June 17, 2019
Is it possible to add functionality to get this list in email?
I’m running AOS 5.1.4 and i don’t seem to be able to location the cmdlets for 5.1.4 i have 5.1.2 any help locating the correct cmdlets would be awesome!!
You can download them from your cluster, go to Prism, click on Admin and Download Cmdlets.
Hi, is there a way to list VM by Date of creation?
[…] vGPU enabled VMs on AHV.I wrote earlier this month and wanted to reuse that script for the VM Inventory script I had written back in 2017 and with the new capabilities of Nutanix AHV it made sense to add the […]