Every user that connects to a published application through Citrix will typically have an active connection. In time these sessions may become disconnected due to improper application closure or your active idle timeout settings may move a session into a disconnected state. Your Citrix farm should have settings in place that would typically clear the disconnected sessions, but occasionally you may run into an issue where a Citrix XenApp session may be stuck in a disconnected state. It is possible to clear these sessions through the GUI, but you can also use Powershell. In order to use Powershell for this to work you must have the Citrix XenApp Server SDK installed on your Citrix Servers.http://community.citrix.com/display/xa/Download+SDKS
- Logon to one of your XenApp 6 Citrix Servers
- Open Windows Powershell with Citrix Xenapp Server SDX (X86)
- Type set-executionpolicy remotesigned enter, choose Y
If you know the session ID and the server that the disconnected session is on you can use the following command to disconnect the session.
Stop-XASession -servername server -sessionID number
You can also script this to disconnect all disconnected sessions on a server regardless of the session ID. However, in order for this to work, you will need a text file that includes the server names that you will want this to run against and saved as a .txt file.
Open Notepad and save the following text as a .ps1 file. I would strongly recommend putting only one server in your text file to this in your environment before running it against all of your servers.
get-content C:\servers.txt | %{
$servername = $_
write-host “Querying server” $servername “…”
get-XASession -ServerName $servername | ? {$_.state -eq “Disconnected”} | % {
$disconnecttime = New-TimeSpan $_.DisconnectTime $(get-date)
$IdleLifespan = new-timespan -minutes 5
if ($disconnecttime -gt $IdleLifespan) {
stop-XASession -session $_.SessionID -servername $servername
write-host “On $servername killed session” $_.SessionId “User” $_.accountname “with idle time” $disconnecttime}
}
}
Enjoy!