Public/Get-DisconnectedSessionDetails.ps1
<#
.SYNOPSIS Retrieves disconnected session details including associated users and machines. .DESCRIPTION This function retrieves disconnected sessions from a specified Citrix Delivery Controller for a given desktop group. It extracts user and machine details from the disconnected session information. .PARAMETER AdminAddress The address of the Citrix Delivery Controller server from which to retrieve session information. .PARAMETER SessionStateChangeTime The cutoff time for session state change. Sessions with a state change earlier than this time are considered. .PARAMETER DesktopGroupName The name of the desktop group for which to retrieve disconnected sessions. .PARAMETER ExcludedADGroups An array of Active Directory group names whose members will be excluded from the session list. .EXAMPLE Get-DisconnectedSessionDetails -AdminAddress "ctxddc001" -SessionStateChangeTime "-0:45" -DesktopGroupName "win10-prod" -ExcludedADGroups @("DL-all", "DL-allFACTS") Retrieves disconnected session details for "win10-prod" desktop group on "ctxddc001" server within the last 45 minutes, excluding users from "DL-all" and "DL-allFACTS" groups. .NOTES Requires Citrix PowerShell SDK and administrative rights to the Citrix environment. #> Function Get-DisconnectedSessionDetails { [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string] $AdminAddress, [Parameter(Mandatory=$true)] [string] $SessionStateChangeTime, [Parameter(Mandatory=$true)] [string] $DesktopGroupName, [Parameter(Mandatory=$true)] [string[]] $ExcludedADGroups ) $DisconnectedSessions = Get-FilteredDisconnectedSessions -AdminAddress $AdminAddress -SessionStateChangeTime $SessionStateChangeTime -DesktopGroupName $DesktopGroupName -ExcludedADGroups $ExcludedADGroups $Results = foreach ($DisconnectedSession in $DisconnectedSessions) { # Extracting user details from the session string $User = ($DisconnectedSession -split '\[|\]')[3].Split('\')[-1].Trim() # Extracting disconnection time details from the session string $DisconnectionTime = $DisconnectedSession -replace '^.*Disconnected for\s+(.*?)\s+on.*$', '$1' $Machines = $DisconnectedSession -split ' ' | Where-Object { ($_ -like 'vdur*' -or $_ -like 'VAUS*' -or $_ -like '*CXA*') } [PSCustomObject]@{ User = $User DisconnectionTime= $DisconnectionTime Machine = $Machines } } $Results } |