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 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?
the Microsoft Support Page for RDS Google… and find this article in your search results…
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.
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:
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…):
…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:
Open a query window, run this query:
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:
delete from rds.RoleRdsh where ServerID = '5';
I also needed to remove the server from the rds.Server table:
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.
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:
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!