HomeNewsletterCommunityMVP FeedToolsArchiveBlogToday's NewsAboutServicesQuick Links★ Pro Subscribe free
← Back to Blog
Scripts & Tools Windows Hello for BusinessIntuneProactive RemediationsPowerShellWHfBSecurity

Deploy Free WHfB Health Scripts to Intune: Six Checks, Five Auto-Repairs, Zero Helpdesk Calls

IA
Imran Awan
6 July 2026

Windows Hello for Business is one of the best security improvements you can deploy across your estate — but it breaks silently, in ways that are genuinely hard to diagnose. A user opens their laptop, taps their PIN, and gets a generic "Something went wrong" screen. They call the helpdesk. The helpdesk resets the PIN. It works. Until it doesn't again, two weeks later, on a different device. This post shows you how to stop that cycle by deploying an Intune Proactive Remediation pair that detects WHfB problems and repairs what a script can safely repair, before the user ever notices.

Download the scripts — GitHub

Both scripts are free and open source. Download them from the Imran76Awan/WHFB repository on GitHub — no sign-in required.

Detect-WHfB.ps1 Remediate-WHfB.ps1 View full repo →
The short version

WHfB breaks silently — PRT expires, NGC keys corrupt, services stop. Here is a Proactive Remediation pair that detects all six failure modes, repairs the ones a script can safely repair, and stops when it cannot, including the trick for running user-context commands from SYSTEM.

What actually breaks in Windows Hello for Business

WHfB has four moving parts that all need to be healthy at the same time. When any one of them drifts, authentication fails:

Watch this post — NotebookLM Audio Overview

Generated with NotebookLM · Subscribe at endpointweekly.com

Watch this post — NotebookLM Audio Overview

Generated with NotebookLM · Subscribe at endpointweekly.com

NGC Key (the credential)

The Windows Hello key stored in C:\Windows\ServiceProfiles\LocalService\AppData\Local\Microsoft\Ngc\. Tied to the user and device. If it gets corrupted or the folder permissions break, WHfB cannot function.

PRT (the SSO token)

The Primary Refresh Token is what gives users seamless SSO to Azure AD resources. WHfB relies on a valid PRT. If the PRT expires or the WAM token broker loses its session, sign-in fails even if the NGC key itself is healthy.

WHfB Services

Four Windows services underpin the stack: KeyIso (CNG Key Isolation), NgcSvc, NgcCtnrSvc, and TokenBroker (Web Account Manager). Any of them in Stopped state = broken authentication.

TPM + Policy

TPM 2.0 must be present, enabled, and ready. WHfB policy must not be explicitly disabled in the registry. BIOS updates can reset TPM ownership. GPO conflicts can set Enabled=0 and silently block provisioning.

How to verify — run dsregcmd /status

Before you deploy anything, run this on an affected device and look at these specific fields. This is the exact output the detection script parses.

Command Prompt (Administrator)
C:\> dsregcmd /status
| Device State
+----------------------------------------------------------------------+
  AzureAdJoined : YES
  DomainJoined : YES
  DeviceId : ████████-████-████-████-████████████
| User State
+----------------------------------------------------------------------+
  NgcSet : YES
  NgcKeyId : ████████████████████████████████████████
  AzureAdPrt : YES
  AzureAdPrtUpdateTime : 2026/07/06 08:41:23
  WamDefaultSet : YES

A broken device shows AzureAdPrt : NO or NgcSet : NO. That is your trigger to remediate.

What broken WHfB looks like in Event Viewer

Before deploying the detection script, you can confirm the failure by looking at two event logs. Open Event Viewer and navigate to Applications and Services Logs → Microsoft → Windows → User Device Registration → Admin. A device with a missing PRT shows Event ID 104:

Error — Event ID 104 — User Device Registration Microsoft-Windows-User Device Registration/Admin
Level: Error
Source: User Device Registration
Event ID: 104
Message: Automatic registration failed at join phase. Exit code: Unknown HResult Error code: 0xcaa2000c
This means the device could not obtain a PRT. WAM returned 0xcaa2000c — authentication token request denied, usually because the token broker service lost its session state.

For NGC key failures, check Applications and Services Logs → Microsoft → Windows → HelloForBusiness → Operational. Event ID 302 tells you WHfB provisioning was attempted and failed:

Warning — Event ID 302 — HelloForBusiness/Operational Microsoft-Windows-HelloForBusiness/Operational
Level: Warning
Source: HelloForBusiness
Event ID: 302
Message: Windows Hello for Business provisioning failed. NGC key creation failed. Error: NTE_BAD_FLAGS (0x80090009)
0x80090009 = the key container is in a bad state. This is the NGC folder corruption pattern — the key store exists but is inaccessible. Step 5 of the remediation script fixes this.
Gotcha: These Event Viewer logs are often empty if the device has never attempted WHfB provisioning — for example, a device where the NGC key was manually deleted. In that case dsregcmd /status is more reliable than Event Viewer for confirming the broken state.

The Detection Script — Detect-WHfB.ps1

The detection script runs 6 checks. It exits 0 (compliant, no action) or 1 (non-compliant, trigger remediation). It can run as SYSTEM or as the logged-on user — PRT and NGC checks are only valid in user context: as SYSTEM the script now skips those two checks and says so, instead of reporting healthy devices as broken. When the PRT is missing it also reads the PRT diagnostics and classifies the cause.

Detect-WHfB.ps1 — Intune detection output
[08:41:22] [INFO ] Device: DESKTOP-██████ | User: DOMAIN\username
[08:41:22] [INFO ] dsregcmd parsed 47 values
 
[08:41:22] [PASS ] Join status : Hybrid Azure AD Joined [████████-████-████-████-████████████]
[08:41:22] [PASS ] PRT : Present (updated: 2026/07/06 08:41:23)
[08:41:22] [PASS ] NGC/WHfB key : Provisioned [KeyId: ████████████████████████████████████████]
[08:41:22] [PASS ] TPM : Present, enabled and ready (Owned: True)
[08:41:22] [PASS ] TPM version : 2.0, Level 0, rev 1.16
[08:41:22] [PASS ] Service [KeyIso] : Running
[08:41:22] [PASS ] Service [NgcSvc] : Running
[08:41:22] [PASS ] Service [NgcCtnrSvc] : Running
[08:41:22] [PASS ] Service [TokenBroker] : Running
[08:41:22] [PASS ] WHfB Policy : Policy key present in registry
 
[08:41:22] [PASS ] --- RESULT ---
[08:41:22] [PASS ] COMPLIANT - WHfB is fully provisioned and healthy
[08:41:22] [PASS ] Checks: Join=OK, PRT=OK, NGC=OK, TPM=OK, Services=OK, Policy=OK
Exit code: 0 — Intune marks device Compliant, no remediation triggered

The script uses a simple dsregcmd /status parser that converts each Key : Value line into a hashtable — no external module required, works on every Windows 10/11 device:

Detect-WHfB.ps1 — dsregcmd parser
function Get-DsregStatus {
    $raw = & dsregcmd.exe /status 2>&1
    $map = @{}
    foreach ($line in $raw) {
        if ($line -match '^s+([A-Za-z0-9_]+)s*:s*(.+)$') {
            $map[$Matches[1].Trim()] = $Matches[2].Trim()
        }
    }
    return $map
}
# Usage
$dsreg = Get-DsregStatus
$prtPresent = $dsreg['AzureAdPrt'] -eq 'YES'
$ngcProvisioned = $dsreg['NgcSet'] -eq 'YES'

For the policy check, the script checks three different registry locations because different versions of Windows and different GPO/MDM paths write to different keys:

Registry Editor — WHfB policy paths (all three checked)
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Policies\PassportForWork
Enabled REG_DWORD 0x00000001 ← Enabled via Group Policy
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\PassportForWork
Enabled REG_DWORD 0x00000001
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PolicyManager\current\device\PassportForWork
Enabled REG_DWORD 0x00000001 ← Written by Intune MDM
If any path has Enabled = 0x00000000, WHfB is disabled by policy → detection exits 1

The Remediation Script — Remediate-WHfB.ps1

📋 Updated 5 November 2026: the scripts on GitHub were rewritten after I checked them against Microsoft's documentation. The old repair 5 took ownership of the Ngc folder and cleared it, ran dsregcmd /cleanupaccounts and triggered UserTask-Roam. That folder is shared by every user on the device, so it removed every enrolled user's Hello credential, and no Microsoft page documents it as a repair. It is gone: step 5 now only reports the Hello key state, and the dsregcmd /forcerecovery fallback is gone too. AzureAdPrt and NgcSet are now read in the user's context, because Microsoft says the command “must run in a user context to retrieve a valid status”; read as SYSTEM, healthy devices looked broken. And before any PRT refresh, the remediation reads the PRT diagnostics: an AADSTS answer such as AADSTS130004 (“The user principal doesn't have the NGC ID key configured”) means Entra ID refused the request, so it stops and exits 1 instead of retrying every schedule. See when the Hello key is missing in Entra and which Hello and PRT fixes are safe to automate. The diagnostics parser has 22 tests, including Microsoft's own sample output. The user-context scheduled-task steps are parse-checked but I have not run them on a live device yet, so pilot first.

The remediation script runs as SYSTEM (the default Intune context) and works through five steps in order. It logs everything to C:\ProgramData\WHfB-Repair\WHfB-Remediate_{computername}_{timestamp}.log. Step 5 only reports the Hello key state: the script never deletes a Hello credential.

5-Step Remediation Sequence
1
Restart WHfB Services
Sets KeyIso, NgcSvc, NgcCtnrSvc, TokenBroker to Automatic start and starts them. Safe — no data loss, instant.
2
Refresh Primary Refresh Token
Reads the PRT diagnostics first and stops (exit 1) if Entra ID answered with an AADSTS error. Otherwise, only if the PRT is missing, runs dsregcmd /refreshprt as the logged-on user via a scheduled task.
3
Hybrid AAD Re-registration
Only runs if the device is domain-joined but not AAD-joined (failed hybrid join). Triggers \Microsoft\Windows\Workplace Join\Automatic-Device-Join.
4
Trigger Intune MDM Sync
3 methods in parallel: COM EnterpriseMgmt tasks, CIM MDM_Client.UpdateSession(), and deviceenroller /AutoEnrollMDM. Re-applies WHfB policy from Intune.
5
Report Hello Key State REPORT ONLY
Reads NgcSet in the user's context and logs it. Changes nothing. If the key is missing, the log says what a person should do next, for example certutil -deletehellocontainer run by that user, not elevated, after preparation.

The clever part: running user-context commands from SYSTEM

Here is the problem with PRT refresh: dsregcmd /refreshprt only works in user context — it reaches the WAM token broker, which is session-bound. But Intune remediations run as SYSTEM. If you call dsregcmd /refreshprt from SYSTEM it silently does nothing.

The solution is Invoke-AsLoggedOnUser — a function that registers a one-time scheduled task under the logged-on user's principal, fires it 3 seconds later, waits 15 seconds, then cleans it up:

Remediate-WHfB.ps1 — Invoke-AsLoggedOnUser
function Invoke-AsLoggedOnUser {
    param([string]$TaskName, [string]$Execute, [string]$Argument = '')
 
    $loggedOnUser = Get-LoggedOnUser # Win32_ComputerSystem.UserName or query session
 
    $action = New-ScheduledTaskAction -Execute $Execute -Argument $Argument
    $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddSeconds(3)
    $principal = New-ScheduledTaskPrincipal -UserId $loggedOnUser `
                                   -LogonType Interactive -RunLevel Limited
    $settings = New-ScheduledTaskSettingsSet `
        -ExecutionTimeLimit (New-TimeSpan -Minutes 3) `
        -DeleteExpiredTaskAfter (New-TimeSpan -Minutes 5)
 
    Register-ScheduledTask -TaskName $TaskName -Action $action `
        -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null
 
    Start-Sleep -Seconds 15 # wait for dsregcmd /refreshprt to complete
    Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue
}
# Called from Repair-PRT:
$taskName = "WHfB-PRT-Refresh-$timestamp"
Invoke-AsLoggedOnUser -TaskName $taskName -Execute 'dsregcmd.exe' -Argument '/refreshprt'
Why this works: The scheduled task runs under LogonType Interactive with the logged-on user as principal. Windows Task Scheduler injects it into the user's active session, giving it access to the WAM token broker that handles Azure AD authentication. The task fires in user context even though the script registering it is running as SYSTEM. This is the same pattern used by SCCM/ConfigMgr for user-context deployments.

Live remediation output (earlier version)

This is the output of the version published in July 2026, before the 5 November changes. It is a real run on a device with a broken PRT and no NGC key, and its step 5 is the old NGC cleanup, which the current script no longer runs. I have not re-run the current version on a live device, so I have not replaced this output. Pre-remediation state: AzureAdPrt=NO, NgcSet=NO. Post-remediation: both restored without a reboot.

Remediate-WHfB.ps1 — Full run output
[09:14:01] [INFO ] WHfB Intune Remediation Script started
[09:14:01] [INFO ] Computer : DESKTOP-██████
[09:14:01] [INFO ] User : SYSTEM
[09:14:01] [INFO ] Log file : C:\ProgramData\WHfB-Repair\WHfB-Remediate_██████_20260706_091401.log
 
[09:14:01] [INFO ] ============================================================
[09:14:01] [INFO ] Pre-Remediation State
[09:14:01] [INFO ] ============================================================
[09:14:02] [INFO ] AzureAdJoined : YES
[09:14:02] [INFO ] DomainJoined : YES
[09:14:02] [INFO ] AzureAdPrt : NO
[09:14:02] [INFO ] NgcSet : NO
[09:14:02] [INFO ] NgcKeyId :
[09:14:02] [INFO ] WamDefaultSet : NO
 
[09:14:02] [INFO ] ============================================================
[09:14:02] [INFO ] Step 1: Restart WHfB Required Services
[09:14:02] [INFO ] ============================================================
[09:14:02] [OK ] CNG Key Isolation (KeyIso): Already running
[09:14:02] [WARN ] NGC Cryptographic Svc (NgcSvc): Stopped — starting...
[09:14:03] [OK ] NGC Cryptographic Svc (NgcSvc): Started successfully
[09:14:03] [WARN ] NGC Container Svc (NgcCtnrSvc): Stopped — starting...
[09:14:04] [OK ] NGC Container Svc (NgcCtnrSvc): Started successfully
[09:14:04] [OK ] Web Account Manager (TokenBroker): Already running
 
[09:14:04] [INFO ] ============================================================
[09:14:04] [INFO ] Step 2: Refresh Primary Refresh Token (PRT)
[09:14:04] [INFO ] ============================================================
[09:14:04] [ACTION] Triggering dsregcmd /refreshprt as logged-on user...
[09:14:04] [ACTION] Scheduling [dsregcmd.exe /refreshprt] as user [DOMAIN\username]
[09:14:22] [OK ] User-context task completed: WHfB-PRT-Refresh-20260706_091401
[09:14:22] [OK ] PRT acquired successfully via WAM refresh
 
[09:14:22] [INFO ] ============================================================
[09:14:22] [INFO ] Step 3: Hybrid AAD Join Re-registration
[09:14:22] [INFO ] ============================================================
[09:14:22] [INFO ] Device is AAD-joined — skipping Hybrid re-registration
 
[09:14:22] [INFO ] ============================================================
[09:14:22] [INFO ] Step 4: Trigger Intune MDM Sync
[09:14:22] [INFO ] ============================================================
[09:14:22] [ACTION] Triggered MDM task: Schedule #1
[09:14:22] [ACTION] Triggered MDM task: Schedule #3
[09:14:23] [OK ] MDM sync triggered via CIM MDM_Client
[09:14:23] [OK ] deviceenroller /AutoEnrollMDM triggered
 
[09:14:23] [INFO ] ============================================================
[09:14:23] [INFO ] Step 5: Clean Stale NGC Keys and Retrigger WHfB Provisioning
[09:14:23] [INFO ] ============================================================
[09:14:23] [ACTION] NGC key missing or broken — running NGC cleanup
[09:14:23] [ACTION] Clearing stale NGC key store at: C:\Windows\ServiceProfiles\LocalService\AppData\Local\Microsoft\Ngc
[09:14:24] [OK ] NGC key store cleared
[09:14:24] [ACTION] Running dsregcmd /cleanupaccounts...
[09:14:25] [ACTION] Triggering NGC UserTask-Roam provisioning task...
[09:14:25] [OK ] NGC provisioning task triggered
[09:14:26] [OK ] Restarted: NgcSvc
[09:14:26] [OK ] Restarted: NgcCtnrSvc
 
[09:14:26] [INFO ] ============================================================
[09:14:26] [INFO ] Post-Remediation State
[09:14:26] [INFO ] ============================================================
[09:14:27] [INFO ] AzureAdJoined : YES
[09:14:27] [INFO ] AzureAdPrt : YES
[09:14:27] [INFO ] NgcSet : YES
[09:14:27] [INFO ] WamDefaultSet : YES
 
[09:14:27] [OK ] Remediation succeeded - PRT present and NGC provisioned
[09:14:27] [INFO ] Remediation script completed - log: C:\ProgramData\WHfB-Repair\...
Exit code: 0 — Intune marks Remediation as Succeeded
Do not clear the TPM to fix WHfB. Clearing the TPM in BIOS or via Clear-Tpm will invalidate your BitLocker protectors on every encrypted drive on the device. If you do not have the BitLocker recovery key saved in Entra ID or AD before you clear it, the drive becomes unrecoverable. The remediation script deliberately never touches the TPM. If TPM health is the actual failure, it needs a BIOS-level fix — not a script.

Deploy to Intune — step by step

Intune Admin Center — Proactive Remediation setup
Devices › Scripts and remediations › Proactive remediations › + Create script package
  1. Name: WHfB Health Monitor
  2. Detection script: Upload Detect-WHfB.ps1 — Run with 64-bit PowerShell: Yes
  3. Remediation script: Upload Remediate-WHfB.ps1 — Run with 64-bit PowerShell: Yes. Run this script using the logged-on credentials: No (SYSTEM) for this package
  4. Schedule: Every 1 hour (or Daily — detection is lightweight)
  5. Scope: Assign to your All Windows Hello for Business users group
One context per package (corrected 5 November 2026): Intune sets Run this script using the logged-on credentials once for the whole script package, not separately for detection and remediation (Microsoft's Remediations page lists it as one setting on the Settings step). The repair package runs as SYSTEM, because starting services and registering scheduled tasks need elevation; in SYSTEM the detection skips the PRT and NGC checks, and the remediation reads them as the signed-in user through a one-off task. For the full detection, including the PRT and the Hello key, create a second, report-only package with Detect-WHfB.ps1 only and the logged-on-credentials setting on Yes.

Reading the logs after remediation

Every remediation run writes a timestamped log to C:\ProgramData\WHfB-Repair\. Open it from a remote session or collect it via Intune device diagnostics. The format is easy to scan — look for [FAIL] or [WARN] entries first, then check whether the Post-Remediation State section shows PRT and NGC as YES.

PowerShell — read and search the latest log file
# Get the most recent log on a device
$latest = Get-ChildItem 'C:\ProgramData\WHfB-Repair' -Filter '*.log' |
    Sort-Object LastWriteTime -Descending | Select-Object -First 1
 
# Show only non-INFO lines (warnings, failures, actions, results)
Get-Content $latest.FullName | Where-Object { $_ -notmatch '[INFO ]' }
 
# Quick pass/fail check — did remediation succeed?
Select-String -Path $latest.FullName -Pattern 'Remediation (succeeded|failed|completed)'
💼 Need this done for you?
Still fighting WHfB helpdesk tickets?

I'll deploy and tune a Proactive Remediation pair like this one for your environment — tailored to your specific failure patterns, not just the six checks covered here.

💬 See how I can help → 📅 Book a free call

Microsoft documentation references

Download these scripts free: Both Detect-WHfB.ps1 and Remediate-WHfB.ps1 are part of the open-source EndpointIQ toolkit on GitHub. The remediation covers every common WHfB failure mode — PRT expiry, NGC corruption, stopped services, failed hybrid join — without touching the TPM or BitLocker. Safe to deploy broadly, not just to devices you already know are broken.
Listen to this post — NotebookLM Audio Overview

Generated with NotebookLM · Subscribe at endpointweekly.com

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

More from EndpointWeekly

Windows Hello for Business
NgcSet Says YES and Windows Hello Still Does Not Work: Triaging…
Windows Hello health lives on eight separate surfaces, and dsregcmd shows you one of…
Technical Guide
Silently Fix a Missing Primary Refresh Token with Intune…
No PRT means no passwordless. The device looks healthy in Intune, compliance shows green,…
Windows Hello for Business
Windows Hello for Business: Why Group Policy Beats Intune, One…
Intune says the Hello setting applied, but the device follows Group Policy. Microsoft's…