HomeNewsletterCommunityMVP FeedToolsArchiveBlogToday's NewsAboutServicesQuick Links★ Pro Subscribe free
← Back to Blog
Technical Guide PRTIntunePowerShellProactive RemediationsAzure ADWHfB

Silently Fix a Missing Primary Refresh Token with Intune Proactive Remediations

IA
Imran Awan
25 June 2026

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.

The short version

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.

Without PRT
  • ✗ WHfB provisioning fails
  • ✗ Conditional Access blocks access
  • ✗ SSO to cloud apps breaks
  • ✗ Outlook / Teams re-authenticate
  • ✗ No error visible in Intune console
With valid PRT
  • ✓ 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:

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.

📋 Note: Both scripts must run as the logged-on user, not SYSTEM. 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.
ScriptRoleRun context
Detect-PRT.ps1Checks 4 health conditions, says why a PRT is missing, exits 0 or 1Logged-on user
Remediate-PRT.ps1Guard, then a staged PRT refreshLogged-on user

What the detection script checks

The script parses dsregcmd /status and evaluates four conditions. Each check outputs a colour-coded result:

  1. AzureAdJoined = YES — device must be Azure AD or Hybrid Joined
  2. DomainJoined = YES — device must be domain joined (Hybrid Join check)
  3. AzureAdPrt = YES — PRT must be present
  4. 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

📋 Updated 5 November 2026: the scripts on GitHub were rewritten after I checked them against Microsoft's documentation. Before it changes anything, 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.

StepActionNotes
GuardRead the PRT diagnosticsAn AADSTS answer (for example AADSTS130004) means stop, exit 1, change nothing
1Restart TokenBroker serviceClears stale in-memory token state. A standard user usually cannot restart services; the script logs a warning and carries on
2dsregcmd /refreshprtStandard PRT refresh — fixes most cases
3Trigger Automatic-Device-Join task + refreshRe-establishes hybrid join state
4Clear WAM token cache (registry) + refreshOpt-in only. Skipped unless PRT_ALLOW_CHANGE_CONTROLLED=1 is set by hand
5dsregcmd /debug /refreshprtVerbose, more thorough internal refresh
6dsregcmd /forcerecovery + re-trigger joinOpt-in only (same switch). Aggressive: resets device registration state
7Diagnostic snapshot + root cause identificationExits 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

Green — OK / PASS Cyan — ACTION Yellow — WARN Red — FAIL Gray — INFO

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

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:

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\.

References

Was this post helpful?
React below — no account needed
Share this post
LinkedIn X / Twitter Reddit Bluesky

More from EndpointWeekly

Technical Guide
Silently Fix Broken Windows Hello for Business with Intune…
NgcSet = NO on a device that looks perfectly healthy is one of the most common WHfB…
Technical Guide
Automating Windows Hello for Business Enrollment with PowerShell…
Devices can be Azure AD joined with a valid PRT and still have Windows Hello completely…
Scripts & Tools
Deploy Free WHfB Health Scripts to Intune: Six Checks, Five…
WHfB breaks silently — PRT expires, NGC keys corrupt, services stop. Here is a Proactive…