You and myself included would hope not, however there may just be a day in your Citrix career when you receive a phone call from a user telling you how they cannot get logged on to Citrix or that their session has frozen and they cannot end the session.
Sure, you might try and log them off via Citrix Director or kill the session via Remote Desktop Services Manager but what if that doesn’t work? What if no matter how many times you click that reset or logoff button nothing happens? What if you try and kill every session process initiated by the user one by one but still one or more of the processes remain?
Now, you are thinking “I will have to restart the XenApp server at this stage”, but you may have 5, 10, 15, 20+ users concurrently sharing that single XenApp server! Not as simple as just restarting because now you are going to affect a larger user base.
You have two options:
- Send all currently logged on users a message asking them to log out. All whilst doing this the affected user has to wait unproductively
- Run a PowerShell command to hide the affected users session so that they can log on to a new session on another XenApp server
Running this PowerShell command, you will have the affected user up and running quickly and you can worry about draining and restarting the server at a more convenient time or without as much urgency.
Within Citrix Studio, launch PowerShell or add the Citrix.Broker.Admin.V2 module to your PowerShell session.
Run command Get-BrokerSession -username DOMAIN\affectedUsername | Set-BrokerSession -hidden $true
Now, run Get-BrokerSession -username DOMAIN\affectedUsername and you can see the Hidden flag will now be set to True. This has set the affected users broken session as hidden. At this stage, the user can launch a Desktop from receiver and it should connect to a different desktop hosting machine in the pool without any fuss.
Dwayne La Rose
October 4, 2016heheh you saved our bacon! I am sticking this in my evernote. I would like to add that using powershell via the Citrix Studio console worked for me.
Shaun
February 16, 2018I also tried to do open PowerShell via citrix studio. Just to confirm, were you trying in citrix director or affected server?
George Spiers
February 16, 2018Launching PowerShell via Studio imports the required PowerShell modules needed to run the “Get/Set-BrokerSession” cmdlets.
George Spiers
October 4, 2016Yes that’s an easier way of launching PowerShell with the correct snapins 🙂 Nice one!
Siva
November 16, 2016Thank you so much for this post. I just wished Citrix Support had known this. Asked for this multiple times.
George Spiers
November 16, 2016You’re welcome!
Admin
November 21, 2016Oh thank you!! I wished I found you earlier – but still applies!!
Patrice Jacques-gustave
January 6, 2017Hello,
Your post is very hepfull, I translate it in my website for french people, thank a lot
Patrice Jacques-gustave
January 6, 2017On http://www.tescitrixoupas.net
George Spiers
January 7, 2017No problem 🙂
Mario
April 11, 2017You saved my days! Thanks a lot!
keith
April 13, 2017Will this work for 6.5?
George Spiers
April 13, 2017Nope only 7.x
abhishek
May 26, 2017what if i want to kill the hung session rather than keeping it hidden?
George Spiers
May 26, 2017Making it hidden is just a workaround until you can restart the server. Ultimately to kill the hung session you reboot the VDA once it has drained of users.
Pablo
August 30, 2017Hi George,
Thanks for your post !!
On my environment, 7.6 work add quotation marks to DOMAIN\affectedUsername
Run command Get-BrokerSession -username “DOMAIN\affectedUsername” | Set-BrokerSession -hidden $true
George Spiers
August 30, 2017Thanks for the feedback.
Shali
February 16, 2018What is username here? On affected username it is understood, but on just username? any idea, please?
George Spiers
February 16, 2018-Username is a parameter of the Get-BrokerSession cmdlet. Example command: Get-BrokerSession -username JGSPIERS\George.Spiers | Set-BrokerSession -hidden $true
Vianney
November 15, 2017This is how this issue was resolved issue in our XenDesktop environment (7.13)
Refer to: Citrix logoff hangs – wfshell.exe
https://jgspiers.com/citrix-logoff-hangs-wfshell/
User Configuration -> Windows Settings -> Scripts (Logon/Logoff).
taskkill /f /im wfshell.exe /t
It was working pretty well and we saw no hung sessions. Unfortunately, the script killed all sessions on the VDI/RDSH whenever a domain admin logged off their session.
Resolution: GPO – Logoff Script (enhanced)
User Configuration -> Windows Settings -> Scripts (Logon/Logoff).
TASKKILL.EXE /FI “USERNAME eq %username%” /IM wfshell.exe /T /F
Workaround:
Force logoff for the hung sessions (wfshell.exe – Printer related)
Open Command Prompt on the affected VDI , you can do this remotely by using:
psexec.exe \\VDICOMPUTERNAME cmd
sc queryex spooler
taskkill /f /pid “PID”
sc queryex cpsvc
taskkill /f /pid “PID”
net stop cpsvc
net stop spooler
net start spooler
net start cpsvc
PsExec can me downloaded from here: http://bit.ly/2z3mdrp
Anonymous
April 10, 2018We use “direct PC access” with the VDA client installed on a physical PC , so users can hotdesk in our office and still get to their PC.
i now have a session stuck (on logging off) on one of them, the machine was actually re-imaged , but a session shows still active . i could hide the session , but it will never release as the machine is no longer available.
any idea to clean this one up ??
Thanks
George Spiers
April 10, 2018So the machine is no longer available, but on Studio/Director there shows one session available? Can you place the machine in maintenance mode then remove it from the Delivery Group and delete it from the Machine Catalog?
Anonymous
April 11, 2018i tried that , but because the session shows as active it doesn’t allow me to remove it 🙁 .
i might try hiding it ,which may allow me to remove it from the delivery and machine group .
George Spiers
April 12, 2018Or power cycle your Delivery Controllers. Quite odd.
Anon
April 26, 2018We would come across this quite often, however on 1 or 2 occasions daily we have a session that we are unable to logoff via studio or director and powershell fails to hide the session. The only thing we can do is drain the server of the user roles and reboot, obviously not ideal with 14/15 users each time. Have you ever experienced this? In XA 6.5 you were able to kill hanging processes via task manager by remoting directly onto the server, even as a full admin this doesn’t appear to work in PVS. Any info would be appreciated.
George Spiers
April 27, 2018I have experienced being unable to log off a session but the hiding of that session has always worked. When you run the command does it not set the Hidden to True?
Anonymous
May 1, 2018It works in the majority of cases, but you would have a few each week that just wouldn’t switch the hidden to true, strange I know! Frustrates the life out of me
Sravan Kumar
May 25, 2018Hi George,
I have a question here, we have only one server which is hosting the application or VDA, in this case what is the solution to remove user session which is frozen already on the server.
I had a same issue in my environment, where in user session got stuck on application hosting server, we don’t get to see user session on server but its visible on studio console.we have restarted the server, still no luck.
Then i have restarted Citrix Desktop Service, solution worked with this.
Do you recommend anything else?
I really appreciate your help here.
George Spiers
May 26, 2018I would just recommend that you upgrade to the latest LTSR or Current Release versions of XenApp and if the issue still persists rebuild your VDA OS. Make sure the OS up to date also, and a supported OS from Microsoft that Citrix also support.
Pingback: Ghost Hunting in XenApp 7.x – Guy Leech's Blog
Anonymous
June 1, 2018Hi, George
If I remove the hung session from database
Will it work?
George Spiers
June 3, 2018I haven’t tried that before. How are you doing that?
Anonymous
June 4, 2018I’ve tried it, it seems to work, but I’m not sure it’s a coincidence.Unfortunately, I haven’t had the hung session for a long time, so there’s no example to try (You know, for a normal conversation,such operations are meaningless).I also want someone to delete the session from the database and verify that it’s actually possible
Wolfgang
October 4, 2018I have used this in cases where the session only exists in Studio but is not actually running on the VDA: https://support.citrix.com/article/CTX221761
Marcus Liotta
June 4, 2018Appears no one considered actually force logging off a user via commandline or powershell.
Here is some quick code to do so.
quser /server:; #to see all users logged in, as verification.
#LOGOFF COMMAND BELOW /V outputs results.
logoff /server: /V
#######################################
Note: in this example, the output is formatted differently for web browsing ease.
Example usage:
quser /server:Server01
USERNAME: user1
SESSIONNAME: rdp-tcp#0
ID: 3
STATE: Active
IDLE TIME: 5
LOGON TIME: 4/3/2018 8:10 AM
LOGOFF rdp-tcp#0 /server:server01 /V
Marcus Liotta
June 4, 2018Apparently my code stripped server01 at multiple points on the last post. here is revised code.
*words* = an indicator this is NOT a command but a direction of what variable to use.
Appears no one considered actually force logging off a user via commandline or powershell.
Here is some quick code to do so.
quser /server:*IPADDRESS OR SERVER NAME*; #to see all users logged in, as verification.
#LOGOFF COMMAND BELOW /V outputs results.
logoff *SESSION_NAME FROM PRIOR COMMAND* /server:*SERVERNAME* /V
#######################################
Note: in this example, the output is formatted differently for web browsing ease.
Example usage:
quser /server:Server01
USERNAME: user1
SESSIONNAME: rdp-tcp#0
ID: 3
STATE: Active
IDLE TIME: 5
LOGON TIME: 4/3/2018 8:10 AM
LOGOFF rdp-tcp#0 /server:server01 /V
Jamaldeen Packeer mohamed
July 31, 2018Hello Marcus, Just curious to know, Is this command will work when the session hosted VDA failed( hardware /OS)?. Does Citrix provide any alternative when the server failed and 50+ sessions goes hung not finding another available server until idle time reached?
Ron
August 24, 2018Hi, I’d like to know if Citrix knows what causes this and are they working on a cure…? We just migrated 6700 concurrent Epic EMR sessions from a 6.5/2008R2 farm to a 7.15/2012R2 farm and are now getting this occasionally. We are going to try the commands as soon as we see it again. Thank you…! Also, we have a 1, 2, 3, or maybe 4 servers a day out of 250 that will just stop taking connections and the logon from RDP or VM console takes 6 to 10 minutes until we Maint. Mode it and bleed users off and either reboot slowwwwly or power down and up again. Normal login times are around 5-6 seconds and app load time is around 5 seconds then boom no more logins. Has anyone had this problem…? Thanks all…!
George Spiers
August 24, 2018When your VDAs stop taking connections, how many sessions do they take before denying any more? Are you on 7.15 CU2?
Anonymous
September 4, 2018Hi George,
When I run the command, Get-BrokerSession -username “DOMAIN\username” | Set-BrokerSession -hidden $true, I got this error “Set-BrokerSession : Selected machine is incompatible with current operation”, what did I miss?
Thanks,
David
George Spiers
September 4, 2018What type of machine is the session hosted on?
John
February 15, 2019Anything for XenApp 6.5?
David
February 20, 2019Hi George, this worked for me and is very useful.
Do you have to reset the hidden flag after user has successfully logged on so that it will have the normal value the next day? Otherwise their session will always be hidden?
Or will it reset to false after next full logoff and on?
George Spiers
February 21, 2019Hi David, the VDA that hosts the hidden session needs to be rebooted. Once rebooted, the hidden session will clear.
Andreas
February 21, 2019Hi,
we got such problems lately with 7.15CU3. User cant reconnect and logoff is not working.
We killed then the dwm process for the user. The process can be found with the session id. This logoff the user.
Your PowerShell code helped us a lot. We had BSODs on 7.15 CU2 and then the users can log on again on another server, when the crashed server is booted and report no users are logged on. We set the hidden flag then for all users on the crashed server.
Thanks,
Bye Andi
webkyaw
March 8, 2019Thank you for this very useful script. I’m surprised this still happens in 7.15 LTSR CU2.
Pingback: Citrix Troubleshooting 101: Frequently Asked Questions | eG Innovations
Jess
July 31, 2019Does anyone know if this is fixed in 7.15 LTSR CU2? We’re on CU2 and currently have this issue and are planning to upgrade to CU4
David
July 31, 2019Hi Jess, it’s much improved. We are on CU3 but the server VDA is on CU4 and we’ve seen a big improvement in this issue, it’s rarely happening now. CU4 seems reliable
Jess
July 31, 2019Does anyone know if this is fixed in 7.15 LTSR CU4? We’re on CU2 and currently have this issue and are planning to upgrade to CU4
Jess
July 31, 2019I meant does this happen on CU4?
Jeff
October 29, 2019I’ve been on CU4 for about 3 months now, with an average of 4000 sessions a day. Today was the first time it happened for me – with just a single user (that we’re aware of).
Jeff
October 29, 2019Sorry, we are actually on CU3.
Barry
November 4, 2019Same issue here – We are running 7.15 LTSR CU4 here and all VDA’s on same CU version.
Citrix Support have no definitive fix/advice other than to upgrade to CU4 which we did and made no difference. Apart from that they are suggesting enabling “active write back” if you use UPM, which we dont.
Annoying but the powershell trick works well..
Anonymous
December 4, 2019Is there a way to add scripting to show what VDA server the user was hung on?
George Spiers
December 14, 2019Get-BrokerSession would show the VDA
David Hendy
April 3, 2020this is doing my nut in. any news on a fix? 7.15 LTSR CU3 here
Senthilkumar
July 14, 2020Hi George,
Thanks for the command it worked for me.
However I have one doubt like when user has single delivery group access means this is working.
But when user had multiple delivery group access I means different desktop group means how we can specify or include a particular server in cmd to restrict logon or make it hidden?
Mmm Warlow
February 19, 2021I just filter my powershell cmd to get the correct session….
something like :
Get-BrokerSession -username shortdomain\userid |Where-Object desktopgroupname -eq “By_Big_desktop_group” |set-brokerSession -hidden $true
Erric Zdzchowski
August 13, 20205 years later and this still saves my bacon!
Adam S
June 8, 2021Many thanks for this tip. Very helpful.
James Baird
September 22, 2021Thank you so much for this work around – I have been using it for years. Today I encountered a really strange occurrence, I hid the problem session and even put the problem server in maintenance mode, but despite this the user’s session still attempts to connect to the previously brokered session on the problem server. The User still shows up in Studio as blank, but when i select the ‘Brokering User Name’ column, lo and behold, it shows the username. It seems it is somehow tied to this value. Guess ill have to wait until this problem server drains off before i can bounce it :/
Brett G
July 21, 2022This script has saved us a bunch.
Is there a way to alter this script where we could reset ALL user sessions on the unregistered server instead of an individual command line basis?
Rino
December 8, 2022Thanks for that. Really saved my day.
MICA
March 8, 2024Many thanks for this tip. Very helpful.