To remove an RDSH host from a Remote Desktop Services farm/cluster, you can use the Server Manager graphical console or the Remove-RDSessionHost PowerShell cmdlet.
To remove an RDSH server from an RDS farm using PowerShell, use the command:
Remove-RDSessionHost -SessionHost @("rdsh2.site.io") -ConnectionBroker rdcb.site.io –verbose
VERBOSE: The specified RD Session Host server will be removed from the session collection.
If the RDSH server to be removed is offline (for example, if it does not boot, it has physically left the hardware server), then when removing it from the RDS farm, an error will appear:
WARNING: Unable to cleanup the RD Session Host server rdsh1.
When trying to remove such a server from hosts with the Remote Desktop Services Host role using Server Manager, an error appears:
Could not remove the configuration. Object reference not set to an instance of an object.
It also becomes impossible to manage the RDS farm from Server Manager, as when deleting the server after deleting the RDSH host from the console, a warning will hang here
The following servers in this deployment are not part of the server pool: rdsh2.site.io
The servers must be added to the server pool.
To gracefully remove a failed RDS host that you do not plan to return to the farm, you must remove its metadata from the RD Connection Broker database.
However, other RDS hosts do not need to be put into RDSH service mode.
To do this, you need to connect to the RDCB database using SQL Management Studio.
- If you are using a local Remote Desktop Connection Broker based on Windows Internal Database (WID), you need to connect to the instance \\.\pipe\MICROSOFT##WID\tsql\query
- If your RDCB is on a SQL Server or SQL Server Always On cluster (when using the highly available RD Connection Broker role ), you need to connect to the appropriate SQL Listener (obtainable with the command Get-RDConnectionBrokerHighAvailability).
Start SQL Management Studio and connect to the database using an account with local administrator rights on the server.
It is strongly recommended that you take an out- of-order SQL backup of the RD Connection Broker database before making any changes.
Expand the RDCms database and look for the following tables, which store entries for RDS farm hosts:
rds.Server - complete list of servers in the Remote Desktop Service farmIn our case, only the RDSH role is running on the server, so you need to delete records about it only from the rds.Server and rds.RoleRdsh tables.
rds.RoleRdsh - list of servers with the RD Session Host role
rds.RoleRdcb - Connection Broker
rds.RoleRdls - RDS License Server )
rds.RoleRdvh - Virtualization Host
rds.RoleRdwa - Web Access Host
Look in the table for the ID of the RDSH server that you want to remove from the RDS farm. In my example, this is ID 3.
Use the following T-SQL query to remove the RDSH server records from both tables in the Connection Broker database:
use RDCms;
delete from rds.RoleRdsh where ServerID = '3';
delete from rds.Server where Id = '3';
Close DB and restart the Server Manager console. Go to the RDS console, update the configuration, and make sure the remote server no longer appears in the available RDSH hosts.
You can also check that this server is no longer in the RDS farm by running the command:
Get-RDServer