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.