Checking PowerShell Cmdlet Connection to Cluster

  • 22 April 2020
  • 2 replies

Userlevel 2
Badge +3

I’m running into an issue with my script to deploy and setup a new VM in AHV.  The part to check for and install Windows Patches can take a while and sometimes I come out of that routine and I’m no longer connected to Prism Element.

I connect with Connect-NTNXCluster…

I’ve seen where you can use $TestConnect = Get-NutanixCluster and then check the .IsConnected parameter.

However in my testing, I last connected yesterday and when I run that this morning it still shows .IsConnected = True so it doesn’t seem like it gets updated.

I’ve also changed the Prism Element GUI settings to a 2 hour timeout but still seems like after way less than that I am no longer connected.  Does that apply to script connections as well?

What is a good/reliable way to test if I'm still connected (outside of trying a command and catching the “unauthorized” error)?




This topic has been closed for comments

2 replies

Badge +2

Also using a variable to test the connection in such a way is probably a bad idea because it saves the variable value from when it was last run. Unless you clear it and rerun the get-nutanixcluster command it will have the data from the last run.

Badge +2

You could use: 

if ($null -eq (get-ntnxclusterinfo))
write-output "Cluster connection closed or some other witty thing"

courtesy of this dude: