This article is demonstration on how to connect to Nutanix using PowerShell and fetch virtual machine inventory. This is the view of Nutanix prism central portal and on the dashboard I can see all the information related to Nutanix objects.
In this prism central I can see virtual machines. My task was to fetch this inventory information details using PowerShell.
Below is the PowerShell script to get information from Nutanix. To use this script install Nutanix.Cli module for PowerShell gallery and connect to prism central with command Connect-NXPrismCentral. Once connected successfully using command Get-NXVM, I can get all the Virtual Machine information in nice table format.
Install-Module -Name Nutanix.Cli -Scope CurrentUser -Confirm:$false -Force Import-Module Nutanix.Cli -Prefix NX Import-Module Nutanix.Prism.PS.Cmds -Prefix NX Import-Module Nutanix.Prism.Common -Prefix NX $prismIP = "xxx.xx.xxx.xx" $username = "admin" $password = 'xxxx@xxxxxxx' $secureString = ConvertTo-SecureString $password -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential ($username, $secureString) Connect-NXPrismCentral -Server $prismIP -UserName $username -AcceptInvalidSSLCerts -ForcedConnection -Password $secureString # $credentials $credentials #-Name xxx-xxxxxxxxxxx Get-NXVM | Select-Object vmName,hostName,uuid,@{N='memoryCapacityGB'; E={[system.math]::Round(($_.memoryCapacityInBytes /1024 /1024 /1024),2)}},` @{N='ipAddresses'; E={$_.ipAddresses -join ','}},` powerState,description,` @{N='VMNIC_Count'; E={$_.virtualNicUuids.Count}},pcHostName, ` @{N='diskCapacityGB'; E={[system.math]::Round(($_.diskCapacityInBytes /1024 /1024 /1024),2)}}, ` @{N='memoryReservedCapacityGB'; E={[system.math]::Round(($_.memoryReservedCapacityInBytes /1024 /1024 /1024),2)}} ,` @{N='VirtualDiskCount'; E={$_.nutanixVirtualDiskUuids.Count}}, ` acropolisVm,vmType,hypervisorType,clusterUuid,runningOnNdfs, @{N='vdiskFilePaths'; E={$_.vdiskFilePaths -join ','}} | Export-Csv -NoTypeInformation c:\temp\nutanixinv-19-01.csv
Download this script Nutanix-PowerShell.ps1 here or it is also available on github.com.
In the above mentioned script I am using Nutanix official PowerShell module. In the next command I am using some another module from Microsoft PowerShell Gallery and fetching information using below commands.
Install-Module -Name TSR.Nutanix.V3.PowerShell Connect-NutanixV3PrismServer -Server $prismIP -Credential $credential Get-NutanixV3Vm | select -expandproperty status | select -ExpandProperty resources
Useful Articles
Powershell Write-Eventlog The source name test does not exist on computer localhost
Powershell New-Object Retrieving the COM class factory for component with CLSID 80040154 Class not registered (Exception from HRESULT 0x80040154 (REGDB_E_CLASSNOTREG))
PowerShell HPE ILO4 Rest API automation examples
Powershell Configure ILO5 using Restful API
Configure Dell iDrac9 Rest API with Powershell
Powershell Dell iDrac redfish Rest API basic authentication
Powershell Convert range of numbers into another list of numbers maintaining ratio
PowerShell slice array into groups of smaller arrays
Powershell web scrapping extract table from html