PowerCLI-Example-Scripts icon indicating copy to clipboard operation
PowerCLI-Example-Scripts copied to clipboard

Get-HVPoolSession - Getting active session on a specific pool

Open AKrawczyk opened this issue 4 years ago • 0 comments

Hi There does not seem to be a way for getting the actives session on a pool. You can get all active session across the whole system.

Here is a possible solution to this

function Get-HVPoolSession { <# .SYNOPSIS Provides a list with all sessions on the local pod (works in CPA and non-CPA) .DESCRIPTION The Get-HVLocalSession gets all local session by using view API service object(hvServer) of Connect-HVServer cmdlet. .PARAMETER HvServer View API service object of Connect-HVServer cmdlet. .EXAMPLE Get-HVLocalSession Get all local sessions .NOTES Author : Wouter Kursten. Modified by : Aaron Krawczyk (Based on filters created by EDURocks) Author email : [email protected] Version : 1.0

===Tested Against Environment====
Horizon View Server Version : 7.0.2, 7.1.0, 7.3.2
PowerCLI Version            : PowerCLI 6.5, PowerCLI 6.5.1
PowerShell Version          : 5.0

#>
[CmdletBinding()]

param( [Parameter(Mandatory = $false)] $HvServer = $null, [Parameter(Mandatory = $true)] [string]$PoolName )

$services = Get-ViewAPIService -HvServer $HvServer if ($null -eq $services) { Write-Error "Could not retrieve ViewApi services from connection object." break }

$pool = get-hvpoolsummary -PoolName $PoolName $DesktopPoolID = $Pool.id if ($null -eq $DesktopPoolID) { Write-Host "Get-HVPoolSession: Could not get Pool id." return $false }

$query_service_helper = New-Object VMware.Hv.QueryServiceService $query = New-Object VMware.Hv.QueryDefinition

$query.queryEntityType = 'SessionLocalSummaryView' $filter = new-object VMware.Hv.QueryFilterEquals $filter.MemberName= "referenceData.desktop" $filter.value = $DesktopPoolID $query.filter = $filter

$SessionList = @() $GetNext = $false $queryResults = $query_service_helper.QueryService_Create($services, $query) do { if ($GetNext) { $queryResults = $query_service_helper.QueryService_GetNext($services, $queryResults.id) } $SessionList += $queryResults.results $GetNext = $true } while ($queryResults.remainingCount -gt 0) $query_service_helper.QueryService_Delete($services, $queryResults.id)

return $sessionlist [System.gc]::collect() }

AKrawczyk avatar Sep 24 '20 08:09 AKrawczyk