Automation

 View Only
  • 1.  Need script to log off all sessions for particular pool

    Posted Aug 26, 2020 10:28 PM

    I feel like this should be easy but for some reason I cannot figure this one out. I need a simple script that will identify all open Horizon sessions from a given pool and then logoff each of those sessions. I would like to schedule this to run once daily at the time which that pools users should be out of office to ensure no sessions remain running.

    Thanks in advance,



  • 2.  RE: Need script to log off all sessions for particular pool

    Posted Aug 27, 2020 06:22 AM


  • 3.  RE: Need script to log off all sessions for particular pool

    Posted Aug 28, 2020 05:20 AM

    ^^ this, mainly the second post has a good script for this. Make sure to force the logoff otherwise disconnected sessions won't be logged off.



  • 4.  RE: Need script to log off all sessions for particular pool

    Posted Aug 28, 2020 05:49 PM

    Thanks for replies. Sorry, I really just cant seem to grasp the API calls for Horizon. I do this kind of stuff daily for AD with PS commands such as get-aduser, set-aduser, etc. For some reason this one is just evading my understanding.

    Thanks to the references given above I have almost got what I need. The script below is working perfectly for identifying the VDI sessions I wish to log off. It seems all I am missing is a one liner to log each of the sessions off as they are found? Any advice how to do this?

    $sessions=(get-hvlocalsession).namesdata

    foreach ($session in $sessions){

    if($session.DesktopName -eq "TESTPOOL1"){

         Write-Host "Connection to TESTPOOL1 found: "  $session.Username 

         #NEED HELP HERE.... NEED TO ADD LOGOFF COMMAND HERE TO LOG OFF THE SESSION IN QUESTION

    }

       }



  • 5.  RE: Need script to log off all sessions for particular pool

    Posted Sep 07, 2020 01:44 PM

    $hvserver=connect-hvserver servername

    $hvservice=$hvserver.extensiondata

    $hvservice.session.session_logoff($sessionid)

    if you have more sessions.Session_LogoffSessions($arrayodsessionids)

    or when they are disconnected/screen locked use Session_LogoffSessionsForced or Session_LogoffForced

    or see: https://www.retouw.nl/2019/07/15/apihow-to-successfully-logoff-users/