User stuck on Citrix Desktop, no way to force log off

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.

1

 


65 Comments

  • Dwayne La Rose

    October 4, 2016

    heheh 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.

    Reply
    • Shaun

      February 16, 2018

      I also tried to do open PowerShell via citrix studio. Just to confirm, were you trying in citrix director or affected server?

      Reply
      • George Spiers

        February 16, 2018

        Launching PowerShell via Studio imports the required PowerShell modules needed to run the “Get/Set-BrokerSession” cmdlets.

        Reply
  • George Spiers

    October 4, 2016

    Yes that’s an easier way of launching PowerShell with the correct snapins 🙂 Nice one!

    Reply
  • Siva

    November 16, 2016

    Thank you so much for this post. I just wished Citrix Support had known this. Asked for this multiple times.

    Reply
    • George Spiers

      November 16, 2016

      You’re welcome!

      Reply
  • Admin

    November 21, 2016

    Oh thank you!! I wished I found you earlier – but still applies!!

    Reply
  • Patrice Jacques-gustave

    January 6, 2017

    Hello,

    Your post is very hepfull, I translate it in my website for french people, thank a lot

    Reply
  • Mario

    April 11, 2017

    You saved my days! Thanks a lot!

    Reply
  • keith

    April 13, 2017

    Will this work for 6.5?

    Reply
    • George Spiers

      April 13, 2017

      Nope only 7.x

      Reply
  • abhishek

    May 26, 2017

    what if i want to kill the hung session rather than keeping it hidden?

    Reply
    • George Spiers

      May 26, 2017

      Making 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.

      Reply
  • Pablo

    August 30, 2017

    Hi 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

    Reply
    • George Spiers

      August 30, 2017

      Thanks for the feedback.

      Reply
    • Shali

      February 16, 2018

      What is username here? On affected username it is understood, but on just username? any idea, please?

      Reply
      • 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

        Reply
  • Vianney

    November 15, 2017

    This 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

    Reply
  • Anonymous

    April 10, 2018

    We 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

    Reply
    • George Spiers

      April 10, 2018

      So 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?

      Reply
      • Anonymous

        April 11, 2018

        i 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 .

        Reply
        • George Spiers

          April 12, 2018

          Or power cycle your Delivery Controllers. Quite odd.

          Reply
  • Anon

    April 26, 2018

    We 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.

    Reply
    • George Spiers

      April 27, 2018

      I 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?

      Reply
      • Anonymous

        May 1, 2018

        It 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

        Reply
  • Sravan Kumar

    May 25, 2018

    Hi 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.

    Reply
    • George Spiers

      May 26, 2018

      I 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.

      Reply
  • Pingback: Ghost Hunting in XenApp 7.x – Guy Leech's Blog

  • Anonymous

    June 1, 2018

    Hi, George
    If I remove the hung session from database
    Will it work?

    Reply
    • George Spiers

      June 3, 2018

      I haven’t tried that before. How are you doing that?

      Reply
      • Anonymous

        June 4, 2018

        I’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

        Reply
      • Wolfgang

        October 4, 2018

        I 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

        Reply
  • Marcus Liotta

    June 4, 2018

    Appears 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

    Reply
    • Marcus Liotta

      June 4, 2018

      Apparently 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

      Reply
      • Jamaldeen Packeer mohamed

        July 31, 2018

        Hello 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?

        Reply
  • Ron

    August 24, 2018

    Hi, 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…!

    Reply
    • George Spiers

      August 24, 2018

      When your VDAs stop taking connections, how many sessions do they take before denying any more? Are you on 7.15 CU2?

      Reply
  • Anonymous

    September 4, 2018

    Hi 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

    Reply
    • George Spiers

      September 4, 2018

      What type of machine is the session hosted on?

      Reply
  • John

    February 15, 2019

    Anything for XenApp 6.5?

    Reply
  • David

    February 20, 2019

    Hi 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?

    Reply
    • George Spiers

      February 21, 2019

      Hi David, the VDA that hosts the hidden session needs to be rebooted. Once rebooted, the hidden session will clear.

      Reply
  • Andreas

    February 21, 2019

    Hi,
    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

    Reply
  • webkyaw

    March 8, 2019

    Thank you for this very useful script. I’m surprised this still happens in 7.15 LTSR CU2.

    Reply
  • Pingback: Citrix Troubleshooting 101: Frequently Asked Questions | eG Innovations

  • Jess

    July 31, 2019

    Does 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

    Reply
    • David

      July 31, 2019

      Hi 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

      Reply
  • Jess

    July 31, 2019

    Does 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

    Reply
    • Jess

      July 31, 2019

      I meant does this happen on CU4?

      Reply
      • Jeff

        October 29, 2019

        I’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).

        Reply
        • Jeff

          October 29, 2019

          Sorry, we are actually on CU3.

          Reply
  • Barry

    November 4, 2019

    Same 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..

    Reply
  • Anonymous

    December 4, 2019

    Is there a way to add scripting to show what VDA server the user was hung on?

    Reply
    • George Spiers

      December 14, 2019

      Get-BrokerSession would show the VDA

      Reply
  • David Hendy

    April 3, 2020

    this is doing my nut in. any news on a fix? 7.15 LTSR CU3 here

    Reply
    • Senthilkumar

      July 14, 2020

      Hi 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?

      Reply
      • Mmm Warlow

        February 19, 2021

        I 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

        Reply
  • Erric Zdzchowski

    August 13, 2020

    5 years later and this still saves my bacon!

    Reply
  • Adam S

    June 8, 2021

    Many thanks for this tip. Very helpful.

    Reply
  • James Baird

    September 22, 2021

    Thank 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 :/

    Reply
  • Brett G

    July 21, 2022

    This 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?

    Reply
  • Rino

    December 8, 2022

    Thanks for that. Really saved my day.

    Reply
  • MICA

    March 8, 2024

    Many thanks for this tip. Very helpful.

    Reply

Leave a Reply to George Spiers Cancel reply