Logoff disconnected users on RDS server with powershell
When you want to manually logoff disconnected users from a Remote Desktop server, you can first query the server for those disconnected sessions and then logoff those sessions.
Logoff disconnected users on RDS server with powershell:
1 2 3 4 5 |
$FQDNOfBroker = "Broker001.company.nl" Import-Module RemoteDesktop $selected = Get-RDUserSession -ConnectionBroker $FQDNOfBroker | Select-Object sessionId,hostserver, username,sessionstate |Out-GridView -PassThru -Title "Select the user to logoff" Invoke-RDUserLogoff -HostServer $selected.HostServer -UnifiedSessionID $selected.SessionId -Force |
Or if the list is to long you can query the disconnected sessions:
1 2 3 4 5 |
$FQDNOfBroker = "Broker001.company.nl" Import-Module RemoteDesktop $selected = Get-RDUserSession -ConnectionBroker $FQDNOfBroker | where Sessionstate -eq 'STATE_DISCONNECTED' | Select-Object sessionId,hostserver, username,sessionstate |Out-GridView -PassThru -Title "Select the user to logoff" Invoke-RDUserLogoff -HostServer $selected.HostServer -UnifiedSessionID $selected.SessionId -Force |
This script queries the RDS broken for sessions and displays a nice (gridview) form. In this form you can select a user to logoff.
That is very nice and clean, I seem to need some help though. We have RDS deployed in our environment. I am using the powershell commands as shown below:
Import-Module RemoteDesktop
$server = ‘serverX01.contoso.com’ —–Obviously this is a fake name to protect the identity of our servers
Get-RDUserSession -ConnectionBroker $Server
and I am getting a message:
“Get-RDUserSession : A Remote Desktop Services deployment does not exist on
serverx01.contoso.com”
I have read a lot of articles that don’t see to offer a clean resolution on this issue. Do you have any ideas what could be the problem?
Thank you!
Hello Ramses,
Did you use the name of the connection broker and not the RDS server itself?
I need a powershell a=command to only logoff disconnected users in one shot if 30 users are in my server 2012 R2 and 15 are stuck as disconnected do you have a command that will disconnect just the 15 at once ?
ignore a=