Public/ForceSessionLogoff.ps1
<#
.SYNOPSIS Forcefully logs off disconnected sessions from Citrix Delivery Controllers. .DESCRIPTION This function forcefully logs off disconnected sessions from specified Citrix Delivery Controllers. .PARAMETER ComputerName An array of computer names representing the sessions to log off. .PARAMETER AdminAddress The address of the Citrix Delivery Controller server. .EXAMPLE ForceSessionLogoff -ComputerName "VDI001", "VDI002" -AdminAddress "DDC1" Logs off sessions for computers "VDI001" and "VDI002" from Citrix Delivery Controller "DDC1". .NOTES Author: Sundeep Eswarawaka #> Function ForceSessionLogoff { [CmdletBinding()] param ( [Parameter(ValueFromPipeline=$true)] [string[]]$ComputerName, [Parameter(Mandatory=$true, Position=0)] [string] $AdminAddress ) $ghostMachines = $ComputerName if ($ghostMachines) { $attemptCounter = 0 $stopCounter = 0 $failCounter = 0 foreach ($ghostMachine in $ghostMachines) { try { $forceResetParams = @{ Action = 'Reset' AdminAddress = $AdminAddress MachineName = $ghostMachine ErrorAction = 'Stop' } New-BrokerHostingPowerAction @forceResetParams > $null $stopCounter++ } catch { Write-Error $_.Exception.Message $failCounter++ } finally { $attemptCounter++ } } $summary = "Force Resets Attempted: ${attemptCounter}`n" + "Reset Tasks Queued: ${stopCounter}`n" + "Reset Tasks Failed: ${failCounter}" if ($attemptCounter) { $summary += "`n`nNote: Power actions are throttled. It may take a few minutes " + "for these tasks to make it to the hosting platform.`n`n" + 'See the corresponding hosting connection(s) config in Citrix Studio for specific details.' } } else { $summary = 'Nothing to do.' } Write-Output $summary Write-Verbose "$(Get-Date): Finished execution." } |