The preceding example shows PowerShell, but the same commands work at the Command Prompt (cmd.exe) equally well. User Profile Disks (UPDs) are great for load balanced RDS farms since it allows users to seamlessly roam from server to server. Open an elevated command prompt. You can see above when Invoke-Command is running with the scriptblock created, it will detect the user logged in and immediately log them off. Here is a quick and easy way to remotely log off end users who are still logged into their computers. Powershell script to see currently logged in users (domain and machine Log Off Remote Sessions in PowerShell | Delft Stack 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 Login to Horizon Connection Server Choose 1 to Login to a Horizon Connection Server That said, Id like to see your PS script for logging off disconnected users. A blog for IT professionals who work with Windows on large networks. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. The session ends and the station is available for log on by any user. This makes it really easy to iterate through each entry and log out only the actual users, and not the system or RDP listener itself which usually just throws an access denied error anyway. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. In this case, Query Session creates a list of all sessions running on the Remote Desktop server, complete with Session ID numbers. We have a tool in place which will be able to run this script across all selected machines, so there is no issue in selecting a target, as local host will be sufficient in this instance. Thanks! Working late at night, getting ready to head home for the day, then realizing that you need to do one more thing. Thanks, though. Then it finally worked. @Darius you don't actually need to be the domain admin. Read more about flags here. For accessing the elements of the array, I'm using a variety of index numbers.