<# .SYNOPSIS Intune Remediations DETECTION script (report only): how people sign in to this PC - PIN, password, fingerprint, face or iris - over the last 7 days. .DESCRIPTION READ-ONLY. Changes nothing on the device. No remediation script is needed. Reads the Security, Biometrics and HelloForBusiness event logs, works out the method of every sign-in and unlock, and writes ONE line of JSON. Intune keeps that line as the detection script output (preRemediationDetectionScriptOutput). Export the device status report from Intune and drop the CSV on the free "Hello Sign-in Fleet" page on EndpointWeekly to see the whole fleet. NO NAMES BY DEFAULT. Microsoft's Remediations page says: "Don't use scripts to collect personal data from devices." So by default the line holds totals for the PC only: how many people signed in, how many sign-ins and unlocks used each method, and how many people used a password. No user name leaves the PC. Set $IncludeUserNames = $true below ONLY if whoever owns privacy in your organisation agrees; then the line also lists each person's counts. Rules, checked in this order for each sign-in or unlock: 1. Exact : HelloForBusiness 5010 within 8 s names the method (ModalityUsedForLogon 0 = PIN, 1 = Face, 2 = Fingerprint, 3 = Iris). Newer builds only. 2. Fingerprint: Biometrics 1004 within 8 s whose message names a fingerprint sensor. 3. Face : Biometrics 1004 that is not a fingerprint, or Biometrics 1702 within 5 s. 4. PIN : HelloForBusiness 5205 or 5702 within 8 s, and no biometric event. 5. Password : none of the above. A password leaves no Hello event, so this is inferred. Sign-ins and unlocks: Security 4624 with logon type 2, 7 or 11, and 4801. A biometric match with no sign-in or unlock near it is an app asking for Windows Hello ("prompt"), counted separately. The Biometric service logs as SYSTEM, so its person is the last sign-in before it. Output (one line, at most 2048 characters, the Intune limit). Default, no names: {"v":2,"days":7,"audit":true,"names":false,"people":1,"pwdPeople":1,"pin":0,"pwd":1,"fp":36, "face":2,"iris":0,"prompts":83,"exact":0,"last":"2026-11-30","err":""} With $IncludeUserNames = $true, two more fields: "users" (each person's counts, at most 8 people and 2048 characters) and "more" (people left out of "users"; they are still in the totals). audit = unlock events were found (unlock auditing is on). If false, PIN and password UNLOCKS are not recorded, so those numbers are too low. err = "security-unreadable" if the Security log could not be read, "hello-log-unreadable" if the Biometrics or HelloForBusiness log could not be read. Either way nothing is counted, because every sign-in would otherwise look like a password. Exit code: 1 when someone signed in with a password, or a log could not be read (Intune lists the PC under "With issues"); 0 otherwise. Set $FlagPassword = $false below to exit 1 only on a read error. Intune settings: Run this script using the logged-on credentials = No (it runs as SYSTEM), Run script in 64-bit PowerShell = Yes, Enforce script signature check = your choice, schedule = Daily. For complete PIN and password numbers, "Audit Other Logon/Logoff Events" (Success) must be on, so that unlocks are recorded. .NOTES Version 1.1, 1 December 2026: no user names unless $IncludeUserNames = $true; device totals always; an unreadable Biometrics or HelloForBusiness log is reported instead of being counted as passwords. EndpointWeekly free tools: https://endpointweekly.com/tools.html ASCII only. Windows PowerShell 5.1 and PowerShell 7. #> [CmdletBinding()] param( [ValidateRange(1, 30)] [int]$Days = 7 ) $ErrorActionPreference = 'Stop' # ---- settings ---- $IncludeUserNames = $false # $true adds each person's name and counts. Agree it with your privacy owner first. $FlagPassword = $true # exit 1 when anyone used a password, so Intune lists the PC under "With issues" $MaxUsers = 8 # with names on: keep the output under Intune's 2048-character limit # Matching windows in seconds (keep them tight: background Hello events are noisy) $WinExact = 8 $WinFinger = 8 $WinFace = 5 $WinKey = 8 $WinDedupe = 3 $MODALITY = @{ '0' = 'PIN'; '1' = 'Face'; '2' = 'Fingerprint'; '3' = 'Iris' } $start = (Get-Date).AddDays(-$Days) $securityFailed = $false $helloFailed = $false function Read-Events([string]$Log, [int[]]$Ids) { try { return @(Get-WinEvent -FilterHashtable @{ LogName = $Log; Id = $Ids; StartTime = $start } -ErrorAction Stop) } catch { $id = [string]$_.FullyQualifiedErrorId if ($id -like 'NoMatchingEventsFound*') { return @() } # a log that does not exist on this PC (no Windows Hello) is empty, not an error if ($Log -ne 'Security' -and $id -like 'NoMatchingLogsFound*') { return @() } if ($Log -eq 'Security') { $script:securityFailed = $true } else { $script:helloFailed = $true } return @() } } function Get-EventData($Evt) { $h = @{} try { $x = [xml]$Evt.ToXml() foreach ($d in $x.Event.EventData.Data) { if ($d.Name) { $h[[string]$d.Name] = [string]$d.'#text' } } } catch { } return $h } $nameCache = @{} function Resolve-Sid([string]$Sid) { if (-not $Sid) { return 'Unknown user' } if ($nameCache.ContainsKey($Sid)) { return $nameCache[$Sid] } $n = $Sid try { $n = (New-Object System.Security.Principal.SecurityIdentifier($Sid)).Translate([System.Security.Principal.NTAccount]).Value } catch { $n = $Sid } $nameCache[$Sid] = $n return $n } function Find-Near([datetime]$Time, $List, [int]$Seconds) { foreach ($item in $List) { if ($item -is [datetime]) { $t = $item } else { $t = $item.Time } if ([math]::Abs(($Time - $t).TotalSeconds) -le $Seconds) { return $item } } return $null } # ---- 1. sign-ins and unlocks ---- $anchors = New-Object System.Collections.ArrayList foreach ($e in (Read-Events 'Security' @(4624, 4801))) { $d = Get-EventData $e $user = $d['TargetUserName']; $dom = $d['TargetDomainName'] if (-not $user) { continue } if ($user -match '\$$') { continue } if ($user -match '^(SYSTEM|LOCAL SERVICE|NETWORK SERVICE|ANONYMOUS LOGON)$') { continue } if ($user -match '^(DWM|UMFD)-\d+$') { continue } if ($e.Id -eq 4624) { $lt = $d['LogonType'] if (@('2', '7', '11') -notcontains $lt) { continue } if ($lt -eq '7') { $kind = 'Unlock' } else { $kind = 'Sign-in' } } else { $kind = 'Unlock' } if ($dom) { $who = $dom + '\' + $user } else { $who = $user } [void]$anchors.Add([pscustomobject]@{ Time = $e.TimeCreated; User = $who; Kind = $kind }) } $dedup = New-Object System.Collections.ArrayList $last = $null foreach ($a in @($anchors | Sort-Object User, Time)) { if ($last -and $last.User -eq $a.User -and [math]::Abs(($a.Time - $last.Time).TotalSeconds) -le $WinDedupe) { if ($a.Kind -eq 'Unlock') { $last.Kind = 'Unlock' } continue } [void]$dedup.Add($a); $last = $a } # ---- 2. the signals ---- $bio = Read-Events 'Microsoft-Windows-Biometrics/Operational' @(1004, 1702) $b1004 = @($bio | Where-Object { $_.Id -eq 1004 } | ForEach-Object { [pscustomobject]@{ Time = $_.TimeCreated; IsFinger = ([string]$_.Message -match 'fingerprint|MOC'); Sid = [string]$_.UserId } }) $b1702 = @($bio | Where-Object { $_.Id -eq 1702 } | ForEach-Object { $_.TimeCreated }) $hfb = Read-Events 'Microsoft-Windows-HelloForBusiness/Operational' @(5205, 5702, 5010) $keyUse = @($hfb | Where-Object { $_.Id -eq 5205 -or $_.Id -eq 5702 } | ForEach-Object { $_.TimeCreated }) $exact = @($hfb | Where-Object { $_.Id -eq 5010 } | ForEach-Object { $dd = Get-EventData $_; [pscustomobject]@{ Time = $_.TimeCreated; Modality = [string]$dd['ModalityUsedForLogon'] } }) # ---- 3. classify and count per person ---- $per = [ordered]@{} function Add-Count([string]$User, [string]$Key, [datetime]$When) { if (-not $per.Contains($User)) { $per[$User] = [ordered]@{ u = $User; pin = 0; pwd = 0; fp = 0; face = 0; iris = 0; prompts = 0; exact = 0; last = '' } } $per[$User][$Key]++ $day = $When.ToString('yyyy-MM-dd') if ($Key -ne 'exact' -and $day -gt $per[$User]['last']) { $per[$User]['last'] = $day } } $KEY = @{ 'PIN' = 'pin'; 'Password' = 'pwd'; 'Fingerprint' = 'fp'; 'Face' = 'face'; 'Iris' = 'iris' } $usedBio = @{} foreach ($a in $dedup) { $t = $a.Time; $method = ''; $isExact = $false $near1004 = Find-Near $t $b1004 $WinFinger foreach ($bb in $b1004) { if ([math]::Abs(($t - $bb.Time).TotalSeconds) -le $WinFinger) { $usedBio[$bb.Time.Ticks] = $true } } $x = Find-Near $t $exact $WinExact if ($x -and $MODALITY.ContainsKey($x.Modality)) { $method = $MODALITY[$x.Modality]; $isExact = $true } if (-not $method -and $near1004) { if ($near1004.IsFinger) { $method = 'Fingerprint' } else { $method = 'Face' } } if (-not $method -and (Find-Near $t $b1702 $WinFace)) { $method = 'Face' } if (-not $method -and (Find-Near $t $keyUse $WinKey)) { $method = 'PIN' } if (-not $method) { $method = 'Password' } Add-Count $a.User $KEY[$method] $t if ($isExact) { Add-Count $a.User 'exact' $t } } # biometric matches with no sign-in or unlock near them = an app asking for Windows Hello $byTime = @($dedup | Sort-Object Time) foreach ($b in $b1004) { if ($usedBio.ContainsKey($b.Time.Ticks)) { continue } if ($b.Sid -and $b.Sid -ne 'S-1-5-18') { $who = Resolve-Sid $b.Sid } else { $prev = $null foreach ($a in $byTime) { if ($a.Time -le $b.Time) { $prev = $a } } if ($prev) { $who = $prev.User } else { $who = 'Unknown user' } } Add-Count $who 'prompts' $b.Time } # ---- 4. one line of JSON for Intune ---- $audit = @($dedup | Where-Object { $_.Kind -eq 'Unlock' }).Count -gt 0 $users = @($per.Values | Sort-Object { -($_.pin + $_.pwd + $_.fp + $_.face + $_.iris) }) $err = '' if ($securityFailed) { $err = 'security-unreadable' } elseif ($helloFailed) { $err = 'hello-log-unreadable' } if ($err) { $users = @() } # never guess: with a log missing, every sign-in would look like a password $tot = [ordered]@{ pin = 0; pwd = 0; fp = 0; face = 0; iris = 0; prompts = 0; exact = 0 } $lastDay = '' $people = 0; $pwdPeople = 0 foreach ($p in $users) { foreach ($k in @($tot.Keys)) { $tot[$k] += $p[$k] } if (($p.pin + $p.pwd + $p.fp + $p.face + $p.iris) -gt 0) { $people++ } if ($p.pwd -gt 0) { $pwdPeople++ } if ($p.last -gt $lastDay) { $lastDay = $p.last } } function To-Json([int]$Keep) { $obj = [ordered]@{ v = 2; days = $Days; audit = $audit; names = [bool]$IncludeUserNames; people = $people; pwdPeople = $pwdPeople } foreach ($k in $tot.Keys) { $obj[$k] = $tot[$k] } $obj['last'] = $lastDay if ($IncludeUserNames) { $obj['users'] = @($users | Select-Object -First $Keep | ForEach-Object { [pscustomobject]$_ }) $obj['more'] = [math]::Max(0, $users.Count - $Keep) } $obj['err'] = $err return ($obj | ConvertTo-Json -Compress -Depth 4) } $keep = [math]::Min($MaxUsers, $users.Count) $json = To-Json $keep while ($json.Length -gt 2048 -and $keep -gt 0) { $keep--; $json = To-Json $keep } Write-Output $json if ($err) { exit 1 } if ($FlagPassword -and $pwdPeople -gt 0) { exit 1 } exit 0