VMware Cloud Community
jasonrobinson
Enthusiast
Enthusiast
Jump to solution

How to constantly checking vCenter connection session?

I need a reliable way to check to see if my vCenter session is active. I am aware of $global:DefaultVIServer.IsConnected, but does anyone know how often that is updated from $true to $false if vCenter goes down? I performed a quick test and connected to a vCenter, validated IsConnected = $true, stopped the vCenter services and it took several mins before it ever updated to IsConnected = $false. I even ran some basic cmds (Get-VM, Get-Cluster, etc) trying to see if that would update IsConnected = $false, but I had no luck.

I have a very long maintenance script that runs throughout the night and I need to be able to check the status of my vCenter session multiple times during the maintenance script. My initial thoughts were to build a function around the status of IsConnected, but based off of my testing and the amount of time it took to update I am not sure that is the correct path.

Does anyone have a better suggestion on checking the status of my vCenter session or know of a way to force IsConnected to update immediately after the vCenter session is killed?

Jason @jrob24
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

This will tell you if the session is connected or disconnected.

$si = Get-view ServiceInstance

$sessMgr = Get-View -Id $si.Content.SessionManager

while($true){

    if($sessMgr.CurrentSession){

        Write-Output "$(Get-Date -Format 'hh:mm:ss') Session connected"

    }

    else{

        Write-Output "$(Get-Date -Format 'hh:mm:ss') Session disconnected"

    }

    sleep 1

    $sessMgr.UpdateViewData('CurrentSession')

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
michelkamp
Contributor
Contributor
Jump to solution

Hi,

It is not reflecting a realtime status. It is only updated when the disconnect is called. So basically its a meaningless property.... ;-(

Michel

0 Kudos
LucD
Leadership
Leadership
Jump to solution

This will tell you if the session is connected or disconnected.

$si = Get-view ServiceInstance

$sessMgr = Get-View -Id $si.Content.SessionManager

while($true){

    if($sessMgr.CurrentSession){

        Write-Output "$(Get-Date -Format 'hh:mm:ss') Session connected"

    }

    else{

        Write-Output "$(Get-Date -Format 'hh:mm:ss') Session disconnected"

    }

    sleep 1

    $sessMgr.UpdateViewData('CurrentSession')

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jasonrobinson
Enthusiast
Enthusiast
Jump to solution

Thanks LucD! I ended up with a solution similar to what you have posted below however I didn't know you could use the UpdateViewData on the current session. I will implement that into my current function.

Thanks for the help!

Jason @jrob24
0 Kudos
RajuVCP
Hot Shot
Hot Shot
Jump to solution

Usefull Script LucD, can we merge the script for mutiple vCenter.

-> In Same script how can we add multiple vCenter

-> How can we convert it in HTML format and send the results to email id.

Thanks.

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
0 Kudos