Automation

 View Only
  • 1.  Need a count of connected View Sessions

    Posted Mar 16, 2020 11:05 PM

    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



  • 2.  RE: Need a count of connected View Sessions

    Posted Mar 17, 2020 06:47 AM

    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.



  • 3.  RE: Need a count of connected View Sessions

    Posted Mar 17, 2020 05:37 PM

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



  • 4.  RE: Need a count of connected View Sessions
    Best Answer

    Posted Mar 19, 2020 10:50 PM

    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



  • 5.  RE: Need a count of connected View Sessions

    Posted Jun 23, 2022 11:07 AM

    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