Skip to content
Menu

Is the RDS Session Host Healthy

Health check for a Remote Desktop Session Host: service and connections, sessions disconnected too long, licensing mode, licence server and grace days, and broker reachability.

Is the RDS session host healthy is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Is the RDS session host healthy. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows Server 2016+ with the Remote Desktop Session Host role; runs as SYSTEM
NeedsPowerShell 5.1; administrator rights; the Remote Desktop Session Host role on this server
Read-onlyReads, changes nothing

What It Does

Run it on the Session Host. A server without the role is SKIPPED. It alerts when the Remote Desktop Services service is not running or the host refuses connections, and when a session has been disconnected for more than MaxDisconnectedHours; sessions are read with the Windows API, not by parsing quser's localized text.

Licensing is set up when the mode is Per User or Per Device and a licence server is configured, locally or by group policy. If it is not, the gap is shown, and it becomes an alert once the grace period has MinGraceDays or fewer left, or cannot be read after three tries.

When broker use is enabled and a broker name is configured, the script checks TCP port 135 from this host. That checks reachability. It does not check whether the broker's services are healthy. It does not count Client Access Licenses, which the license server holds, and never signs anyone out.

It keeps no state. Run it daily so the grace-period warning arrives weeks before users are locked out.

Before You Run It

  • Run it as SYSTEM on each Remote Desktop Session Host.
  • Set MinGraceDays to how much warning you want before the grace period ends.

Type and Risk

  • Type: Monitor. It checks one condition. It exits 1 when it finds the problem, so your RMM can alert on it, 0 when all is well, and 2 when it could not run.
  • Risk: Low. It reads and changes nothing.
  • Restart: It never restarts the machine.
  • Typical run: Under 30 seconds.
  • Example answer: "Sessions CONTOSO\jsmith (session 3) disconnected 41.2 h (limit 24 h); Licensing Grace period 12 days left; no licence server configured"
  • Tested before listing on a Windows Server 2025 domain controller (VM) with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • MaxDisconnectedHours: Alert on a session that has been disconnected for more than this many hours. Whole number, 1 to 8760. Default 24.
  • MinGraceDays: When licensing is not set up, alert once the grace period has this many days or fewer left. Whole number, 0 to 365. Default 30.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

test-rds-host-health.ps1 · 1012 lines · 51.9 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.