VMware Cloud Community
wboaz
Enthusiast
Enthusiast
Jump to solution

Need a count of connected View Sessions

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

Reply
0 Kudos
1 Solution

Accepted Solutions
wboaz
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
wboaz
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
wboaz
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
mat1234
Contributor
Contributor
Jump to solution

If anyone is looking at this article, this didn't work for me. The Get-HVQueryResult cmdlet is part of the VMware.Hv.Helper module, you might need to install it manually.

If you get an error Connect-HVServer : Could not establish trust relationship for the SSL/TLS secure channel with authority "Your connection broker server"

use the command Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false

 

Reply
0 Kudos