There is a failure pattern that breaks Windows Hello for Business silently and completely: the device is Hybrid Joined, the TPM is fine, the NGC key is provisioned — and WHfB still doesn't work. The reason is almost always the same. The Primary Refresh Token is missing.
No PRT means no passwordless. The device looks healthy in Intune. Compliance shows green. But the user gets a sign-in prompt they can't complete, calls the service desk, and an engineer manually runs dsregcmd /refreshprt on their machine. This post covers the two-script Intune Proactive Remediation I built to detect and automatically fix that — before the user ever notices.
No PRT means no passwordless. The device looks healthy in Intune, compliance shows green, but WHfB provisioning silently fails. Here is the Intune remediation that detects it, says why, and refreshes the PRT only when a refresh can help, without touching a healthy device.
What is a Primary Refresh Token?
The PRT is a long-lived token issued by Azure AD to a device when a user signs in. It sits in the credential store and is silently used to obtain access tokens for cloud resources — including the token that Windows Hello for Business needs to complete PIN setup.
AzureAdJoined : YES
DomainJoined : YES
AzureAdPrt : NO <-- PRT missing
AzureAdPrtExpiryTime : <-- empty
That output from dsregcmd /status is the exact problem. A device can be perfectly Hybrid Joined, have a healthy TPM, and have the NGC key fully provisioned — but if the PRT is gone, WHfB provisioning cannot complete. Authentication to Azure AD resources also silently degrades: Outlook prompts for credentials, Teams re-authenticates, SSO stops working.
- ✗ WHfB provisioning fails
- ✗ Conditional Access blocks access
- ✗ SSO to cloud apps breaks
- ✗ Outlook / Teams re-authenticate
- ✗ No error visible in Intune console
- ✓ WHfB PIN setup completes
- ✓ Conditional Access passes
- ✓ SSO works across all Azure AD apps
- ✓ Silent token refresh every ~4 hours
- ✓ 90-day validity, auto-renewed
Why PRT goes missing
The PRT can disappear for several reasons, none of which produce a clear alert:
- Hybrid join breaks after re-imaging — the device re-joins the domain but the AAD registration does not complete cleanly
- AAD Connect sync lag — the device object isn't synced to Azure AD yet at the time of sign-in
- TokenBroker state corruption — stale in-memory token cache blocks new PRT acquisition
- WAM cache corruption — stale registry entries in the Web Account Manager cache conflict with new token requests
- Expired PRT not renewed — Microsoft says a PRT “is valid for 90 days and is continuously renewed as long as the user actively uses the device”, and the CloudAP plugin renews it every 4 hours during Windows sign-in. It doesn't renew while the device is offline (corrected 31 October 2026: an earlier version said 14 days)
- Conditional Access changes — a new CA policy blocks the PRT issuance flow silently
The solution: two scripts, one Intune Remediation
The automation runs as an Intune Proactive Remediation. The detection script checks PRT health and exits 0 or 1. If non-compliant, Intune automatically runs the remediation script.
dsregcmd /refreshprt only works in user context — running it as SYSTEM silently does nothing. Remediate-PRT.ps1 now refuses to run as SYSTEM (exit 1, nothing changed) and Detect-PRT.ps1 warns that its result is not valid there.| Script | Role | Run context |
|---|---|---|
Detect-PRT.ps1 | Checks 4 health conditions, says why a PRT is missing, exits 0 or 1 | Logged-on user |
Remediate-PRT.ps1 | Guard, then a staged PRT refresh | Logged-on user |
What the detection script checks
The script parses dsregcmd /status and evaluates four conditions. Each check outputs a colour-coded result:
- AzureAdJoined = YES — device must be Azure AD or Hybrid Joined
- DomainJoined = YES — device must be domain joined (Hybrid Join check)
- AzureAdPrt = YES — PRT must be present
- PRT expiry — PRT must not be expired or expiring within 4 hours (proactive refresh)
Exit 0 = compliant (Intune takes no action). Exit 1 = non-compliant (Intune runs the remediation script).
What the remediation script does
Remediate-PRT.ps1 now reads the PRT diagnostics in dsregcmd /status. If the Server Error Description field holds an AADSTS code, Entra ID received the request and refused it. AADSTS130004 is the one Microsoft defines as “The user principal doesn't have the NGC ID key configured”. No refresh can fix that, so the script stops, changes nothing and exits 1, which keeps the device visible in Intune. See when the Hello key is missing in Entra. The Web Account Manager cache clear (step 4) and dsregcmd /forcerecovery (step 6) no longer run from a schedule: I found no Microsoft page that documents either as a repair, so they run only if you set PRT_ALLOW_CHANGE_CONTROLLED=1 by hand on one device. See which Hello and PRT fixes are safe to automate. The two scripts also did not parse in Windows PowerShell 5.1, which Intune uses to run them (em dashes in the files were read as quote marks); that is fixed. The diagnostics parser has 22 tests, including Microsoft's own sample output. I have not yet run the scripts end to end on a live device, so pilot before you widen.The remediation script first runs a guard, then works through up to six escalating steps. Each step checks whether the PRT is restored before moving to the next, and it stops the moment the PRT is obtained. The guard reads the PRT diagnostics: if Entra ID answered with an AADSTS error, the script stops there and changes nothing. After step 2 it reads the diagnostics again for the same reason.
| Step | Action | Notes |
|---|---|---|
| Guard | Read the PRT diagnostics | An AADSTS answer (for example AADSTS130004) means stop, exit 1, change nothing |
| 1 | Restart TokenBroker service | Clears stale in-memory token state. A standard user usually cannot restart services; the script logs a warning and carries on |
| 2 | dsregcmd /refreshprt | Standard PRT refresh — fixes most cases |
| 3 | Trigger Automatic-Device-Join task + refresh | Re-establishes hybrid join state |
| 4 | Clear WAM token cache (registry) + refresh | Opt-in only. Skipped unless PRT_ALLOW_CHANGE_CONTROLLED=1 is set by hand |
| 5 | dsregcmd /debug /refreshprt | Verbose, more thorough internal refresh |
| 6 | dsregcmd /forcerecovery + re-trigger join | Opt-in only (same switch). Aggressive: resets device registration state |
| 7 | Diagnostic snapshot + root cause identification | Exits 1, log saved for escalation |
Steps 4 and 6 are opt-in. Step 4 clears the Web Account Manager token cache and step 6 runs dsregcmd /forcerecovery, which resets the device registration state and re-triggers the hybrid join. I found no Microsoft page that documents either as a repair, and Microsoft's dsregcmd troubleshooting page does not list /forcerecovery. The script skips both and logs why. To run them, on one device with the user present, set $env:PRT_ALLOW_CHANGE_CONTROLLED = '1' in that PowerShell session first. An Intune schedule cannot set that variable, so they never run from one.
Colour scheme
Step-by-step: Add to Intune Proactive Remediations
Step 1 — Create a new script package
Go to Intune > Devices > Remediations > + Create script package. Name it something like PRT Health Check and Repair.
Step 2 — Upload both scripts
- Detection script file:
Detect-PRT.ps1 - Remediation script file:
Remediate-PRT.ps1 - Run script in 64-bit PowerShell: Yes
- Run using logged-on credentials: Yes — this is critical, both scripts must run as the user
Step 3 — Set the schedule
Set the schedule to Every 1 hour or Daily. Hourly catches a broken PRT before it affects the user's session.
Step 4 — Assign to your device group
Assign to your Hybrid AAD Joined Windows 10/11 device group. Start with a pilot group before rolling to the full estate.
Reading the results
After deployment, go to Devices → Remediations → your package → Device status:
- Without issues — detection exited 0, PRT is healthy
- With issues (remediated) — detection exited 1, remediation ran and obtained a PRT
- Remediation failed, stopped on purpose — the last line of the script output reads
PRT-REMEDIATE result=stopped issue=HelloKeyNotInEntra aadsts=AADSTS130004(or anotherAADSTScode). Entra ID refused the sign-in and a script cannot fix that, so the device stays visible as needing a person. See when the Hello key is missing in Entra - Remediation failed — check the log at
%LOCALAPPDATA%\PRT-Repair\on the device. The log includes a root cause indicator: broken hybrid join, missing device object in AAD, no DC line-of-sight, or Conditional Access blocking token issuance
PRT vs WHfB: These two remediations work together. The PRT remediation fixes the token layer. The WHfB remediation fixes the NGC key layer. Run PRT first — there is no point repairing the NGC key if the PRT is missing.
Get the scripts
Both scripts are available on GitHub alongside the WHfB remediation scripts.
🔗 View on GitHub — Imran76Awan/WHFB/PRT Remediation
Tip: To test locally before deploying to Intune, run Detect-PRT.ps1 first to confirm exit code 1, then run Remediate-PRT.ps1 in the same user session. The colour-coded output (green = OK, cyan = ACTION running, red = FAIL) lets you follow each step in real time. The full log is written to %LOCALAPPDATA%\PRT-Repair\.