Question

Checking PowerShell Cmdlet Connection to Cluster

  • 22 April 2020
  • 2 replies
  • 842 views

Userlevel 1
Badge +1

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)?

 

Thanks!

 


2 replies

Badge +1

You could use: 

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

courtesy of this dude: 

http://blog.myvirtualvision.com/2019/03/27/how-to-add-a-cd-rom-drive-and-mount-an-iso-file-via-powershell-to-an-ahv-hosted-vm/

Badge +1

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.

Reply