Sample Exchange

 View Only

Manage-Horizon-Sessions-By-User 

May 07, 2021 07:26 PM

Manage Horizon Sessions By User

Manage-Horizon-Sessions-By-User

This script will allow you to list and manage the active Horizon sessions for a user

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

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

Updated May 7, 2021


Script Overview

This is a PowerShell script that uses PowerCLI and the View-API to query Horizon sessions. You can search for sessions by user and log them off, disconnect them or send them a message

Script Usage

Run Manage-Horizon-Sessions-ByUser.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

Return Horizon Sessions By Username

Choose 2 to return Horizon Sessions. You will be prompted for the username to search for.

Sessions

If you enter an invalid username or the user has no sessions you will be shown that no sessions could be found for that user

Login

If there are sessions you will shown the number of sessions also with details.

Login

You will now be presented with a menu to manage the sessions you can:

  1. Logoff all sessions for the user
  2. Disconnect all sessions for the user
  3. Send all of the users sessions a message
  4. Exit without making changes

Select a number to proceed with that action.

3 - Send a Message to all sessions for user - you will be prompted for what message you would like to send.

Login

When you click enter you message will be sent and output will show which sessionIDs it was sent to

Login

2 - Disconnect all sessions for user

When you select this option, all of the users sessions will be disconnected and you will receive output on which sessionIDs it was applied to

Login

After we run that action we can look at the sessions again and see they are disconnected.

Login

1 - Logoff all sessions for user

When you select this option, all of the users sessions will be logged off and you will receive output on which sessionIDs it was applied to

Login

If we search again for sessions for this user, you can see that there are none.

Login


#PowerShell
#MIT
#Horizon
#Horizon

Statistics
0 Favorited
2 Views
1 Files
0 Shares
0 Downloads
Attachment(s)
zip file
manage-horizon-sessions-by-user-main.zip   461 KB   1 version
Uploaded - Apr 09, 2024

Tags and Keywords

Comments

Sep 29, 2023 12:35 PM

Hello. I know this is an older post but if anyone is reading this I wanted to report that after selecting option 2 to return sessions by username, I enter in my username and the query returns "There are ## total sessions" for me and on this test it stated there were 24 sessions for me. However, I'm only logged into one and the return list simply shows me all the user sessions that are currently active.
I have installed the latest version of PowerCLI and we're on Horizon View 8.8.0 build - 21073894, version 2212.

Related Entries and Links

No Related Resource entered.