Solved

Failing to execute Set-NTNXVMPowerState from PoSH Script - access denied

  • 7 March 2019
  • 1 reply
  • 1978 views

Badge +1
I've written a PoSH script which does the following.
  1. Authenticates to Prism Central V3 API
  2. Calls /category/query API to get a list of VM uuid's that are members of the PROD category.
  3. Write this list of uuid's to a string
  4. Connect to the NTNX cluster using Nutanix PowerShell cmdlets.
  5. Iterate through the above string and execute Set-NTNXVMPowerState against the uuid's.
Steps 1 - 4 work as expected. Step 5 seems to iterate through the list as it should but when I put in the Set-NTNXVMPowerState command to be executed, it throws an access denied error.

Once the script gives the error, the powershell connection looks like it locks the account and you cannot execute any commands.

If I comment out the foreach loop, and just execute a normal PoSH cmdlet (after the Connect-NTNXCluster) such as Get-NTNXClusterInfo, it works fine.

I have tried both my account (which has Prism admin rights) and the Prism Central admin account with no luck.

So 2 questions:
  1. Any ideas what the problem is with the code?
  2. Would there be any issues with the starter license in executing Set-NTNX* commands?
See the link below for the script code:
https://github.com/leepryor/Nutanix_Powershell/blob/master/Shutdown-Categorized-VMs.ps1
icon

Best answer by devwangler 12 March 2019, 01:54

View original

This topic has been closed for comments

1 reply

Badge +1
I worked out the problem.

You have to invoke the api via Prism.

When you run the PS cmdlets, these need to be run against the cluster itself. If you're using my code above, i've already made the changes required for this.