How to Establish PowerShell Connection to Nutanix and Execute your 1st Query

In my article Nutanix Automation, Policies and the SDDC I discussed how Nutanix exposes all features and functions via REST API, enabling programmatic access to datacenter services within mainstream enterprises.
The current list of features and services that can be fully managed by programmatic access is long and include the following:

  • Alerts
  • Authconfig
  • Cluster
  • Containers
  • Disks
  • Events
  • Hosts
  • Http proxies
  • Protection Domains (Disaster Recovery)
  • Remote Sites
  • SNMP
  • Storage Pools
  • Vdisks
  • VMs
  • Vstores

In this article I demonstrate how each of these API calls can be used for powerful datacenter automation using PowerShell. Currently PowerShell calls must be done using the Invoke-RestMethod method, but Nutanix will soon be releasing a fully featured PowerShell snap-in, making automation more efficient and easier.
Establishing a connection to PRISM and retrieving cluster information:
[css lang=”plain” autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ padlinenumbers=”false” gutter=”true” smarttabs=”true” toolbar=”true” language=”true”]
add-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

$Uri = ""
$Header = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+":"+$password ))}
$username = "username"
$password = "password"
Invoke-RestMethod -Method Get -Uri $Uri -Headers $Header
Results for the Invoke-RestMethod method using PrismGateway/services/rest/v1/cluster. (Click to Enlarge)


Try replacing /cluster with any of the methods listed above and you will start to get the individual properties for VMs, VMDKs, vStores, Storage Pools etc…
This article was first published by Andre Leibovici (@andreleibovici) at


1 ping

Skip to comment form

  1. To get the connection to authenticate correctly I needed to put the $username and $password instantiations before the $Header instantiation.

    Also it is worth noting that Invoke-RestMethod was introduced in Powershell 3.0.

    • Dominic on 05/19/2014 at 9:10 am

    I try the code about on a Windows 8.1 client and getting the following error

    Invoke-RestMethod : HTTP Status 401 – Bad credentials
    type Status report
    message Bad credentials
    description This request requires HTTP authentication (Bad credentials).
    Apache Tomcat/6.0.35
    At C:\POC\PS.ps1:21 char:1
    + Invoke-RestMethod -Method Get -Uri $Uri -Headers $Header
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

    I know the username and password is correct. What am I missing?

  2. @Dominic, I had that before with complex passwords. Try setting your user password to something simpler, without special characters, and see if works. Powershell require special handling with special characters in a string.

    • mark on 03/22/2016 at 7:40 am

    ditto on Josh’s comment

  1. […] « How to Establish PowerShell Connection to Nutanix and Execute your 1st Query […]

Leave a Reply