Sample Exchange

 View Only

Logoff-Horizon-Sessions-Disconnected-Longer-Than 

May 12, 2021 02:02 PM

Manage Horizon Disconnected Sessions.  Show all disconnected sessions and show all sessions that have been disconnected longer than specified hours.  You can then logoff those sessions. Sesssion Start and Disconnect Time are shown in the local time zone where the script is run.

Logoff-Horizon-Sessions-Disconnected-Longer-Than

Show and Logoff Horizon Sessions Disconnected longer than hours specified.

There is no support for this tool - it is provided as-is

Please provide any feedback directly to me - my contact information:

Chris Halstead - Staff Architect, VMware
Email: chalstead@vmware.com
Twitter: @chrisdhalstead

Thanks to Wouter Kursten for the feedback on supporting over 1,000 sessions.

The code to support that is based off of his post here: https://www.retouw.nl/2017/12/12/get-hvmachine-only-finds-1000-desktops/

This script requires Horizon 7 PowerCLI - https://blogs.vmware.com/euc/2020/01/vmware-horizon-7-powercli.html

Updated May 12, 2021


Script Overview

This is a PowerShell script that uses PowerCLI and the View-API to query Horizon sessions. The script will show all disconnected sessions, or sessions that have been disconnected longer than specified hours. You can then logoff those sessions. Also, all logon and disconnect time are shown in the local time zone.

Script Usage

Run Horizon-Logoff-Disconnected-Sessions.ps1

Menu

Login to Horizon Connection Server

Choose 1 to Login to a Horizon Connection Server

  • Enter the FQDN of the server when prompted to "Enter the Horizon Server Name" hit enter

  • Enter the Username of an account with Administrative access to the Horizon Server you are connecting to when prompted to "Enter the Username" hit enter

  • Enter that users Password and click enter

  • Enter that users Domain and click enter

    You will see that you are now logged in to Horizon - click enter to go back to the menu

    Login

Show all Disconnected Sessions

Choose 2 to return all Disconnected Horizon Sessions. The logon and disconnect time will be shown in the local time zone where the script is run.

Sessions

Show / Logoff Sessions Disconnected more than X Hours

Choose 3 to return all Sessions Disconnected longer than the number of hours you specify. You will be prompted to enter the number of hours - this will show all sessions that have been disconnected longer than the number of hours you specify. In this example we will choose 8 hours.

Sessions

Sessions

You will now be presented with a menu to 1 Logoff all sessions or 2 to do nothing and return to previous menu.

Sessions

Choose to Logoff the sessions and they are logged off immediately.

Sessions

We can now see that there are no sessions that have been disconnected over 8 hours.

Sessions


#Horizon
#MIT
#PowerShell
#PowerCLI

Statistics
0 Favorited
2 Views
1 Files
0 Shares
0 Downloads
Attachment(s)
zip file
logoff-horizon-sessions-disconnected-longer-than-main.zip   267 KB   1 version
Uploaded - Apr 09, 2024

Tags and Keywords

Related Entries and Links

No Related Resource entered.