wboaz
Enthusiast
Enthusiast

Need a count of connected View Sessions

Jump to solution

Restarting another old thread here as the previous shows as answered and this is a bit different.

With COVID-19 our management is trying to keep a close eye on the resources consumed by teleworkers and how well it is scaling.

In the below I can get a count of all sessions that are coming in from the external connection servers. Unfortunately the NamesData Class doesn't have the SessionData.SessionState. I need to be able to pull both the SessionState and SecurityGatewayDNS at the same time.

If both:

SessionData.SessionState -eq CONNECTED

SecurityGatewayDNS -like "view.company.org"

Then I have an active, external, View session.

Anyone know how to get the connection state of the guests? This gets a count of both connected and disconnected.

Import-Module -Name VMware.VimAutomation.HorizonView

Connect-HVServer connectionserver

$query = New-Object "Vmware.Hv.QueryDefinition"

$query.queryEntityType = 'SessionLocalSummaryView'

$qSrv = New-Object "Vmware.Hv.QueryServiceService"

$rslt = $qSRv.QueryService_Query($global:DefaultHVServers[0].ExtensionData,$query)

$rslt | Select-Object -ExpandProperty Results |

Select-Object -ExpandProperty NamesData |

where-Object {$_.SecurityGatewayDNS -like "view.company.org"} |

Select-Object -Property UserName,MachineOrRDSServerName,MachineOrRDSServerDNS,SecurityGatewayAddress |

Measure-Object |

Select-Object count

0 Kudos
1 Solution

Accepted Solutions
wboaz
Enthusiast
Enthusiast

This works:

Import-Module -Name VMware.VimAutomation.HorizonView

Connect-HVServer viewextcon01


$results = Get-HVQueryResult SessionLocalSummaryView

$count = 0

foreach ($result in $results) {

    if ($result.namesdata.SecurityGatewayDNS -eq "view.company.com" -AND $result.SessionData.SessionState -eq "CONNECTED" ) {

        $count++

    }

}

   Write-Host $count

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership

When you use the VMware.HV.Helper module I think a simple Get-HVMachineSummary -State CONNECTED would give you the result you are looking for.

See Automating VMware Horizon 7 with VMware PowerCLI for more details.

If you can not use the module, the queries you could use are present in there.


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

0 Kudos
wboaz
Enthusiast
Enthusiast

Well, that tells me I have 1200 clients connected but not from where and not as a count.

0 Kudos
wboaz
Enthusiast
Enthusiast

This works:

Import-Module -Name VMware.VimAutomation.HorizonView

Connect-HVServer viewextcon01


$results = Get-HVQueryResult SessionLocalSummaryView

$count = 0

foreach ($result in $results) {

    if ($result.namesdata.SecurityGatewayDNS -eq "view.company.com" -AND $result.SessionData.SessionState -eq "CONNECTED" ) {

        $count++

    }

}

   Write-Host $count

View solution in original post

0 Kudos