Skip to content
Menu

SSO and Teams Sign-In Broken - Entra Join and PRT Health

Runs dsregcmd /status and checks the join state, device certificate dates and, in a user's context, the Primary Refresh Token, alerting on a broken join.

SSO and Teams sign-in broken - Entra join and PRT health 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 SSO and Teams sign-in broken - Entra join and PRT health. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, Windows 11, Windows Server 2016+; runs as SYSTEM or a user
NeedsPowerShell 5.1; dsregcmd.exe (in Windows); the Task Scheduler service
Read-onlyReads, changes nothing

What It Does

The script is read-only. It runs dsregcmd /status and checks the join state, which can be Entra ID joined, hybrid joined, domain only, Entra registered only or workgroup; the device certificate's validity dates, with an alert if it is expired or not yet valid; whether the device key is protected by the TPM, which is shown and never alerted; and the tenant name and MDM enrolment URL, which are shown.

In a user's context it also reads the signed-in user's Primary Refresh Token and its expiry. A joined PC whose user has no PRT cannot do single sign-on to Microsoft 365 and Teams. The device facts are the same for every account, so they are read correctly when an RMM runs the script as SYSTEM. But dsregcmd run as SYSTEM reports SYSTEM's own, always empty, token state, which would be a false alert. So when run as SYSTEM with someone signed in, the script runs dsregcmd inside that user's session, with a one-shot scheduled task for the user that is deleted straight afterwards. If nobody is signed in, or the user's check cannot be run, the PRT row says it was not checked. Local accounts are reported as having no PRT expected. A missing or expired token alerts when the user's token is checked.

It checks only the console user, or the user of a desktop shell. The dsregcmd field names and YES or NO values are used as English text, and this has not been confirmed on a non-English Windows. If the AzureAdJoined field is not in the output, the script ends with an error rather than guessing.

It is SKIPPED when there is no Entra ID join, including workgroup, domain-only and Entra-registered-only PCs. Set RequireEntraJoin to true to alert on those instead, for a fleet that must all be Entra ID joined or hybrid joined.

Before You Run It

  • Use RequireEntraJoin only for a fleet that must all be Entra ID joined or hybrid joined.
  • Run it while a user is signed in if you want the PRT checked. With nobody signed in it is not checked.
  • Test it on a non-English Windows PC before you rely on it there. The field names are used as English text.
  • Schedule it in your RMM and alert on exit 1.

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 15 seconds; up to 60 seconds more when it reads the signed-in user's token.
  • Example answer: "Hybrid joined to Contoso; device certificate valid to 2035-06-01; no PRT for CONTOSO\ana"
  • Tested before listing on Windows 11 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.

  • RequireEntraJoin: Alert, instead of skipping, when the PC is not Entra ID joined or hybrid joined (workgroup or domain only). true or false. Default false.

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-entra-join-health.ps1 · 919 lines · 47.1 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.