Jump to content
Welcome to our new Citrix community!
  • 0

Powershell script to logoff diconnected sessions in XenApp 7.5


Bharath KN

Question

Hi All

 

has any one run powershell script to logoff the disconnected sessions from XenApp servers?

 

I ran this powershell command but ends with error. can someone help.

 

 

PS C:\Windows\system32> Get-XASession -Farm | Where-Object { $_.State -eq "Disconnected"} | Stop-XASession
Get-XASession : Citrix commands must be executed at the Citrix server or using remoting. Make sure that your user
account is a Citrix administrator and that the IMA service is started.
At line:1 char:1
+ Get-XASession -Farm | Where-Object { $_.State -eq "Disconnected"} | Stop-XASessi ...
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-XASession], InvalidOperationException
    + FullyQualifiedErrorId : ImaInteropError,Citrix.XenApp.Commands.GetSessionCmdlet

 

 

Thanks

Bharath

Link to comment

6 answers to this question

Recommended Posts

  • 2

That looks like a XenApp 6.5 PowerShell command but you're posting in a XenApp 7.5 forum. 

 

I think you need: Get-BrokerSession, SessionState, and Stop-BrokerSession

 

Also, the Get-BrokerSession command had a -filter parameter so you can filter it on the server rather than using Where-Object to filter it.

 

get-brokersession -filter {sessionstate -eq "Disconnected"} | stop-brokersession

  • Like 2
Link to comment
  • 0

I ran that command but no luck..

 

I dont see get-brokersession command in powershell.

 

PS C:\Windows\system32> get-brokersession -filter {sessionstate -eq "Disconnected"} | stop-brokersession
get-brokersession : The term 'get-brokersession' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ get-brokersession -filter {sessionstate -eq "Disconnected"} | stop-brokersession
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (get-brokersession:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Link to comment
  • 0

I ran the above given commands and it ran successfully.. but looks like i dont get any result.. 

 

PS C:\Windows\system32> get-brokersession -filter {sessionstate -eq "Disconnected"} | stop-brokersession
PS C:\Windows\system32> get-brokersession -filter {sessionstate -eq "Disconnected"} | stop-brokersession
 
can we get the disconnected session in complete Site? and then log them such disconnected users?
 
Thanks
Bharath
Link to comment
  • 0

I Just now tried to fetch all the disconnected sessions in the Farm using get-xasession , but the cmdlet returns both Active and disconnected sessions. Can anyone from Citrix really confirm, weather this cmdlet really works at all or not? I am quite sure that the below format is quite correct to the best and true to my knowledge.

 

Get-XASession -Farm | select ServerName,State | where {{ $_.State -eq "Disconnected" }} | Format-Table -AutoSize

 

I won't mind if someone can prove me wrong or assist me to create the correct command for my script I am trying to write.

xasession_cmdlet.jpg

Link to comment
  • 0
On 7/12/2018 at 8:07 PM, Arunava Dey1709157342 said:

I Just now tried to fetch all the disconnected sessions in the Farm using get-xasession , but the cmdlet returns both Active and disconnected sessions. Can anyone from Citrix really confirm, weather this cmdlet really works at all or not? I am quite sure that the below format is quite correct to the best and true to my knowledge.

 

Get-XASession -Farm | select ServerName,State | where {{ $_.State -eq "Disconnected" }} | Format-Table -AutoSize

 

I won't mind if someone can prove me wrong or assist me to create the correct command for my script I am trying to write.

xasession_cmdlet.jpg

 

First step is to drop the double braces around your where statement, second -eq is not meant for string comparisons, more for numbers or Boolean statements .  Try the following:
get-xasession -farm | select servername,state | ? {$_.state -like "disconnected"} | ft -auto

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...