none
Unable to select all disconnected users from session's list in Windows Server 2012&2012R2 RRS feed

  • Question

  • Hi,

    We have High availability environment with connection broker server in it.

    When ever we have some releases for our software, we need to logoff all sessions.

    Here we are unable to select all users sessions at a time from the collections of connection broker and for now selecting one by one and logging them off.

    Is there any solution for choosing all disconnected or Idle or Active users for performing required task.

    Please check the attached screen shot for sessions example.

    Thanks,

    Sri


    Srinivasu M

    Thursday, August 14, 2014 8:02 AM

All replies

  • Theres no remote desktop services console in W2012 and W2012R2, the way to do it is via powershell, I attach the script please saved it as .ps1 and run it as administrator. Please let me know and give a vote and if is resolving please close it.

    CHeers 

    Corwin Ott Irola

    <#
     .SYNOPSIS
     Select Remote Session State and logs off the user sessions.
     
     .DESCRIPTION
      Select REMOTE SESSION STATE (DISCONNECTED/ACTIVE/IDLE/ALL) AND LOGS OFF THE USERS
     SESSIONS.
     
     .NOTES
      FILE NAME: RDSESSIONSUPPORT.PS1
     #>
      
    Write-Host "=============================================="
     Write-Host ""
     Write-Host "          PLEASE SELECT YOUR OPTION          "
     Write-Host ""
     Write-Host "============================================="
     Write-Host ""
     Write-Host " A. End All Disconnected Remote User SESSIONS"
     Write-Host " B. End All Active Remote User SESSIONS"
     Write-Host " C. End All Idle Remote User SESSIONS"
     Write-Host " D. End All Remote User SESSIONS"
     Write-Host " X. Cancel and Quit"
     $choice = Read-Host "Enter Selection"
    
    Switch ($choice) {
     "A" {$RDSessions = Get-RDUserSession | Where-Object -Filter {$_.SessionState -eq 'STATE_DISCONNECTED'} }
     "B" {$RDSessions = Get-RDUserSession | Where-Object -Filter {$_.SessionState -eq 'STATE_ACTIVE'} }
     "C" {$RDSessions = Get-RDUserSession | Where-Object -Filter {$_.SessionState -eq 'STATE_IDLE'} }
     "D" {$RDSessions = Get-RDUserSession}
     "X" {Exit}
     }
    
    If (!$RDSessions)
     {
     Write-Host "No Remote User Sessions found with Choice:" $choice
     }
     Else
     { # Start Loop
     Foreach ($RDSession in $RDSessions)
     {
     Invoke-RDUserLogoff -UnifiedSessionID $RDSession.SessionId -HostServer $RDSession.HostServer -Force
     Write-Host "The User" $RDSession.UserName "is logged off from" $RDSession.HostServer "server"
     } # End Loop
     } # End If
     
    Read-Host {"Press Enter to Exit <---"}

    Tuesday, January 6, 2015 5:58 PM
  • Thanks for your reply.

    here I need to logout user which are in disconnected mode only.

    I think the script you have given is for all users in the list.

    let me know if any more.

    Thanks,

    Sri


    Srinivasu M

    Wednesday, January 7, 2015 5:24 AM
  • When you run the script it give you 4 options (Disconnected Users,Active Users,Idle Users, All Users) so you choose which option you will like, in you case should be option A. Thanks Corwin
    Wednesday, January 7, 2015 1:09 PM
  • Nice little script, it works great on local broker server.  Thank you!  This will be the base for hitting multiple brokers and collections for me.  Again, Thank you!.
    Thursday, October 27, 2016 4:25 PM
  • Theres no remote desktop services console in W2012 and W2012R2, the way to do it is via powershell, I attach the script please saved it as .ps1 and run it as administrator. Please let me know and give a vote and if is resolving please close it.

    CHeers 

    Corwin Ott Irola

    <#
     .SYNOPSIS
     Select Remote Session State and logs off the user sessions.
     
     .DESCRIPTION
      Select REMOTE SESSION STATE (DISCONNECTED/ACTIVE/IDLE/ALL) AND LOGS OFF THE USERS
     SESSIONS.
     
     .NOTES
      FILE NAME: RDSESSIONSUPPORT.PS1
     #>
      
    Write-Host "=============================================="
     Write-Host ""
     Write-Host "          PLEASE SELECT YOUR OPTION          "
     Write-Host ""
     Write-Host "============================================="
     Write-Host ""
     Write-Host " A. End All Disconnected Remote User SESSIONS"
     Write-Host " B. End All Active Remote User SESSIONS"
     Write-Host " C. End All Idle Remote User SESSIONS"
     Write-Host " D. End All Remote User SESSIONS"
     Write-Host " X. Cancel and Quit"
     $choice = Read-Host "Enter Selection"
    
    Switch ($choice) {
     "A" {$RDSessions = Get-RDUserSession | Where-Object -Filter {$_.SessionState -eq 'STATE_DISCONNECTED'} }
     "B" {$RDSessions = Get-RDUserSession | Where-Object -Filter {$_.SessionState -eq 'STATE_ACTIVE'} }
     "C" {$RDSessions = Get-RDUserSession | Where-Object -Filter {$_.SessionState -eq 'STATE_IDLE'} }
     "D" {$RDSessions = Get-RDUserSession}
     "X" {Exit}
     }
    
    If (!$RDSessions)
     {
     Write-Host "No Remote User Sessions found with Choice:" $choice
     }
     Else
     { # Start Loop
     Foreach ($RDSession in $RDSessions)
     {
     Invoke-RDUserLogoff -UnifiedSessionID $RDSession.SessionId -HostServer $RDSession.HostServer -Force
     Write-Host "The User" $RDSession.UserName "is logged off from" $RDSession.HostServer "server"
     } # End Loop
     } # End If
     
    Read-Host {"Press Enter to Exit <---"}

    Good script!

    Only I add "Import-Module RemoteDesktop", "-CollectionName<CollectionName>" to Get-RDUserSession and change "$RDSession.SessionId" to "$RDSession.UnifiedSessionId".


    Have a nice day !!!
    DPM 2012 R2: Remove Recovery Points
    DPM blog
    System Center
    Hyper-V

    Monday, August 7, 2017 7:32 PM