After working with RDS (Remote Desktop Services, previously known as “Terminal Services”, also referred to “The biggest pain in the rear and the only way to get more than two remote desktop sessions on a server because Microsoft either hates admins, hates this product, or both”) I have come to the conclusion that Microsoft really needs to make something which should be simple, simple. Alas it isn’t simple. And today’s topic…

You have an RDS licensing and management server… you have several Session Host servers as part of your deployment. At some point one of those servers died and was henceforth removed from the domain. It’s gone, never to return. You login to manage Remote Desktop Services licensing… and are told that a bunch of servers are missing from the management pool.

Something along these lines:

The following servers in this deployment are not part of the server pool:
servername.domain.local
The servers must be added to the server pool.

Instead of MS just letting you manage RDS, you have to fix this first. Fine… you go to add them back in but wait…. you have that server which was a session host which died a horrible death and therefore cannot be added back in… What now?

You visit the Microsoft Support Page for RDS Google… and find this article in your search results…
https://support.microsoft.com/en-us/help/2910155/remote-desktop-services-tools-are-not-functional-after-you-remove-a-se

Yay! It requires powershell but hey, it looks like an easy fix…

Nope… the Powershell Command fails with the ever so helpful “Object reference not set to an instance of an object” message.

More Google….

Surprise, you are one of a long line of lucky admins that has had this problem and thankfully one of them figured it out by delving into the arcane mysteries of Windows, Remote Desktop Services, and the Windows Internal Database… where all of the RDS deployment information is kept.

Links from other admins have fixed this problem:
https://dave.harris.uno/unable-to-remove-deleted-session-hosts-from-rds2012-deployment/
https://www.petenetlive.com/KB/Article/0001415

Here is the long and short of how to fix this problem (shamelessly condensed from the above two articles):

First you have to install SQL Server Management studio on your RDS management/licensing server/all of your RDS connection brokers (if your have more than one, follow the below steps, rinse and repeat…):
https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-2017

…Go get coffee (like… drive to Starbucks and read a book about how to replace Windows Server with a Linux alternative) because between the 800 MB download and 2 hour install process (what exactly is the bloody SSMS installer doing all this time???) that is now SSMS 2017 you will have plenty of time.

When you come back, assuming you are not now facing a random BSOD just for fun and because it’s that time of year…. (make sure you have a server snapshot/checkpoint/backup/whatever… then…) open up SSMS RUN AS ADMINISTRATOR and connect here:

\\.\pipe\MICROSOFT##WID\tsql\query

Open a query window, run this query:

SELECT TOP 1000 [Id],[Name] FROM [RDCms].[rds].[Server]

Look at the list of servers in the NAME column. Find your dead server and note the ID number in the ID column. For this example, lets say my id is “5”. The ID for your system will most likely be different so don’t just copy and paste the below commands, make sure you change the ID to what you actually need to remove.

—-MAKE SURE YOU HAVE A DATABASE BACKUP OR SYSTEM CHECKPOINT OR SYSTEM BACKUP OR SOMETHING BEFORE PROCEEDING—-

Run the following query to remove the dead SESSION HOST server from the database:

use RDCms;
delete from rds.RoleRdsh where ServerID = '5';

I also needed to remove the server from the rds.Server table:

use RDCms;
delete from rds.Server where Id = '5';

Note, the above covers the session host role. If you have a server with other roles there are other tables you can look at and delete by id. Just right-click on the table (after drilling down in object explorer in to the RDCms database) and “Select Top 1000 rows” to see if your server ID is listed there.

Relevant tables:
rds.RoleRdcb (Connection Broker)
rds.RoleRdls (License Server)
rds.RoleRdsh (Session Host)
rds.RoleRdvh (Virtualisation Host)
rds.RoleRdwa (Web Access Host)

You can use the following powershell command from an elevated powershell prompt (before and after to confirm the server is gone) to list out RDS servers:

get-RDServer

Conclusion:
Once everything is deleted out of the DB, close SSMS and then close and re-open Server Manager. Now you can get to your Remote Desktop Services management screen and get on with your life!

Thank you to the admins who did all the brain-crunch work to sort this out! This material was mostly compiled from the links above in the article!

1 of 1

6 comments on: Remove Dead RDS Session Host Server – Otherwise You Can’t Manage Remote Desktop Services

  1. François
    Reply

    thanks ! and very humoristic paper…

  2. Patrick
    Reply

    Thanks for this. A frustrating issue solved.

    • nbeam
      Reply

      Yeah, I was slightly frustrated when trying to solve this… which probably comes through in the article just a tad 🙂

  3. Michel
    Reply

    Awesome, thanks for sharing this!

  4. Afterburned
    Reply

    …or add a DNS entry in for the missing server (give it an IP that isn’t being used) and add it in to Server Manager using the DNS option. Remove at your leisure later.

    • nbeam
      Reply

      Thank you for that! Sounds much cleaner. Will give that method a go the next time this trips us up. 🙂

Join the discussion

Your email address will not be published. Required fields are marked *