9

Get more insight into your Horizon idle sessions

This is a short blog about Idle session in the VMware Horizon Administrator console.

For some time now, the Idle status of VDI Desktop, RDSH Desktops and RDSH Applications have been part of the dashboard in the VMware Horizon Administrator console. The number of Idle sessions, especially in large environments, changes approximately every minute and the number of sessions can therefore vary considerably every time the dashboard refreshes. That is why I was curious about the data behind this dashboard. Which sessions are idle and how long have they been idle?

Te screenshot above shows the Connected and Disconnected and Idle sessions. The Connected and Disconnected sessions can be easily traced when clicking through on the “View” button. A lot of information is shown as you can see below.

But unfortunately it is not possible to get further information from the console at this time about the sessions that are Idle.
To create more insight, I started working with PowerCLI in combination with the Horizon API. So, I created the following script.

# Variables
$ConnectionServer = Read-Host = 'Connection Server:'
$User             = Read-Host -Prompt 'Username:'
$Password         = Read-Host -Prompt 'Password:' -AsSecureString
$Domain           = Read-Host -Prompt 'Domain:' 

# Connect to Horizon Connection Server
$HVServer              = Connect-HVServer -Server $ConnectionServer -User $User -Password $Password -Domain $Domain -Force

# Query Horizon
$ViewAPI               = $global:DefaultHVServers[0].ExtensionData
$query_service         = New-Object "Vmware.Hv.QueryServiceService"
$query                 = New-Object "Vmware.Hv.QueryDefinition"
$query.queryEntityType = 'SessionLocalSummaryView'
$Sessions              = $query_service.QueryService_Query($ViewAPI,$query)

# Show Session/Names data
$Sessions.Results | Format-table -AutoSize -Property @{N = 'Username'; E = {$_.NamesData.UserName}},@{N = 'Desktop Pool'; E = {$_.NamesData.DesktopName}},@{N = 'Machine or RDS'; E = {$_.NamesData.MachineOrRdsServerName}}`
,@{N = 'Client Type'; E = {$_.NamesData.ClientType}},@{N = 'Client Version'; E = {$_.NamesData.ClientVersion}},@{N = 'Session Type'; E = {$_.sessiondata.sessiontype}},@{N = 'Session State'; E= {$_.sessiondata.sessionstate}}`
,@{N = 'Idle Duration'; E = {$_.sessiondata.IdleDuration}}

This script then gives the following output:

With the help of this information it is in any case clear who is Idle and for how long. It turns out that after a minute in which there has been no interaction with the application or desktop, the session becomes Idle.

This “Idle Sessions dive” has given me more insight. I hope it’s of some use to you too.

Roderik de Block

 

Roderik de Block

9 Comments

  1. Thank your for sharing that great script.

    I got the result but in idle duration output i got empty, do you know why ?

    appreciate your help.

    • Could you provide more information. I used this script in multiple Horizon 8 environments withou any issue.

      • Thank you for replying to me much appreciate.
        what kind of information’s you need so i can provide.
        Im using Horizon 7.13

  2. Also if i need to ask for idle duration greater than 2 hours so how the script will be ?
    it would be useful also if you put export the result in the script.

    Thank you in advance.

    • The last line will look like this. This line contains a filter which will select machines with a Idle time of 120 minutes and more.

      $Sessions.Results |? {$_.sessiondata.IdleDuration -gt 120} | Format-table -AutoSize -Property @{N = ‘Username’; E = {$_.NamesData.UserName}},@{N = ‘Desktop Pool’; E = {$_.NamesData.DesktopName}},@{N = ‘Machine or RDS’; E = {$_.NamesData.MachineOrRdsServerName}}`
      ,@{N = ‘Client Type’; E = {$_.NamesData.ClientType}},@{N = ‘Client Version’; E = {$_.NamesData.ClientVersion}},@{N = ‘Session Type’; E = {$_.sessiondata.sessiontype}},@{N = ‘Session State’; E= {$_.sessiondata.sessionstate}}`
      ,@{N = ‘Idle Duration’; E = {$_.sessiondata.IdleDuration}}

      • unfortunately i got empty result with this modifications.
        using Horizon 7.13

        • Unfortunately I don’t have a 7.13 environment and I can’t test that specific scenario. It seems that the “IdleDuration” attribute does not exist or is not populated in your environment.

  3. Thank you RODERIK for helping,
    I did it in this way in below and it works in 7.13 just wanted to share it with you 🙂

    —session duration here in millisecond—

    $Sessions.Results |? {$_.sessiondata.lastSessionDurationMS -gt 7200000} | Format-table -AutoSize -Property @{N = ‘Username’; E = {$_.NamesData.UserName}},@{N = ‘Desktop Pool’; E = {$_.NamesData.DesktopName}},@{N = ‘Machine or RDS’; E = {$_.NamesData.MachineOrRdsServerName}}`
    ,@{N = ‘Client Type’; E = {$_.NamesData.ClientType}},@{N = ‘AgentVersion’; E = {$_.SessionNamesData.agentVersion}},@{N = ‘Session Type’; E = {$_.sessiondata.sessiontype}},@{N = ‘Session State’; E= {$_.sessiondata.sessionstate}}`
    ,@{N = ‘Idle Duration’; E = {$_.sessiondata.lastSessionDurationMS}} ,
    #@{N = ‘Session Protocol’; E = {$_.sessiondata.sessionprotocol}}
    @{N = ‘GW’; E = {$_.sessiondata.clientAddress}}

Leave a Reply

Your email address will not be published. Required fields are marked *