Get the Total Number of Active Sessions in a Host Pool (Azure Virtual Desktop)

Here’s a quick PowerShell script to get the total number of active sessions in a Azure Virtual Desktop host pool.

Select-AzSubscription -SubscriptionName "YourSubscriptionName"

# Set the variables for the host pool name and resource group name
$hostPoolName = "HPname"
$resourceGroupName = "RGname"

# Retrieve the user sessions for the host pool
$userSessions = Get-AzWvdUserSession -ResourceGroupName $resourceGroupName -HostPoolName $hostPoolName

# Get the number of active sessions
$sessionCount = ($userSessions | Where-Object {$_.SessionState -eq "Active"}).Count

# Output the total number of sessions
Write-Host "Total session count for host pool $hostPoolName is: $sessionCount"
Share or Save this: