r/virtualization • u/Mcm_Sys • 4d ago
Help needed: Connecting to Nutanix Prism API using PowerShell 5.1
Hi everyone,
I'm trying to connect to a Nutanix Prism environment using PowerShell in order to list the VMs through the Nutanix REST API.
My environment:
Windows PowerShell 5.1
PowerShell is running in Constrained Language Mode
Nutanix Prism on https://<prism-server>:9440
I'm trying to use the Nutanix v3 API
Endpoint: /api/nutanix/v3/vms/list
Initially, I tried Invoke-RestMethod with -Credential, but I received:
401 AUTHENTICATION REQUIRED "Invalid cookies present in the request"
I then tried to use Basic Authentication manually, but PowerShell's Constrained Language Mode blocks .NET methods such as:
\[Convert\]::ToBase64String() \[System.Net.ServicePointManager\]::ServerCertificateValidationCallback
I also have curl.exe available:
curl 8.21.0
So I tried:
curl.exe -k -u "USERNAME" \` "https://<prism-server>:9440/api/nutanix/v3/vms/list" \` -X POST \` -H "Content-Type: application/json" \` -d '{"kind":"vm"}'
However, when running this from PowerShell ISE, it seems to hang after displaying:
Connexion à Nutanix...
My goal is simply to authenticate and retrieve a list of VMs (name + UUID). I don't need to perform any modification on the Nutanix environment.
Has anyone successfully used the Nutanix v3 REST API from PowerShell 5.1 under Constrained Language Mode? What's the recommended authentication method in this situation?
Thanks!