//
you're reading...

XenApp

Disconnected and down XenApp sessions

There’s a great blog post on the Citrix community website that provides answers to FAQs related to the XenApp CTP. The blog provides the following code to find down or disconnected sessions.

$sessions = Get-XASession
foreach($session in $sessions){
    if($session.Protocol -eq "Ica" -and $session.State -ne "Listening" -and $session.State -ne "Active")
    {
        Write-Host $session.SessionName $session.ServerName $session.AccountName $session.BrowserName $session.State $session.Protocol
    }
}

I decided to test the code out but I only got a list of disconnected sessions.

I modified the code to display all sessions on “MyServer”.

Get-XASession | where-object{$_.ServerName -eq "MyServer"} | ft SessionId,SessionName,ServerName,AccountName,State -AutoSize

I ran the code against a server with a hung down session. I got a list of active and disconnected sessions which is similar to the output from the “Citrix blog” script. The down session and the RDP/ICA “listeners” weren’t returned from the command.

I modified the code…

Get-XASession -ServerName "MyServer" | ft SessionId,SessionName,ServerName,AccountName,State -AutoSize

Now I get a list with the listeners and the down session!

Here’s a comparison of the output.

image

If you’re looking for down sessions make sure you use “Get-XASession -ServerName MyServer”.

Here’s the final tweaked code.

$servers = Get-XAServer -onlineonly -zonename MyZone
foreach($server in $servers){
  $sessions = Get-XASession -ServerName $server
  foreach($session in $sessions){
    if($session.Protocol -eq "Ica" -and $session.State -ne "Listening" -and $session.State -ne "Active"){
      Write-Host $session.SessionName $session.ServerName $session.AccountName $session.BrowserName $session.State $session.Protocol
}