Skip to content

Commit f52366a

Browse files
committed
fix: correct Intune policy matching in drift report to avoid null-name false match
Get-CIPPDrift compared raw .displayName/.name properties across four OR clauses to detect whether a tenant's Intune policy was already covered by a template. Most Intune policy types (compliance policies, device configurations, app protection policies, group policy configurations, Windows Update profiles) have no .name property at all - only displayName. Since PowerShell's $null -eq $null evaluates to $True, the .name -eq .name clause falsely matched as soon as any configured template lacked a .name property, marking almost every tenant-only Intune policy as already templated and suppressing its deviation. Conditional Access matching was unaffected because it only ever compares .displayName, with no .name fallback/collision risk - matching the reported symptom where CA drift worked but Intune drift did not. Fix: compare the already-computed, normalized effective names ($TemplatePolicyName/$TenantPolicyName, which fall back from displayName to name) instead of the raw properties, and require both sides to be non-empty before treating them as a match. Fixes KelvinTegelaar/CIPP#6347
1 parent 45bd6c9 commit f52366a

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Modules/CIPPCore/Public/Get-CIPPDrift.ps1

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,14 @@ function Get-CIPPDrift {
379379
foreach ($TemplatePolicy in $TemplateIntuneTemplates) {
380380
$TemplatePolicyName = if ($TemplatePolicy.displayName) { $TemplatePolicy.displayName } else { $TemplatePolicy.name }
381381

382-
if ($TemplatePolicy.displayName -eq $TenantPolicy.Policy.displayName -or
383-
$TemplatePolicy.name -eq $TenantPolicy.Policy.name -or
384-
$TemplatePolicy.displayName -eq $TenantPolicy.Policy.name -or
385-
$TemplatePolicy.name -eq $TenantPolicy.Policy.displayName) {
382+
# Compare using the resolved effective names (displayName, falling back to name)
383+
# and require both sides to be non-empty. Most Intune policy types (compliance
384+
# policies, device configurations, group policy configs, etc.) only expose
385+
# displayName and have no .name property at all, so comparing raw .name values
386+
# directly (as before) compared $null -eq $null, which is $true in PowerShell -
387+
# causing every tenant policy to falsely "match" the first template as soon as
388+
# any template lacked a .name property, suppressing all tenant-only deviations.
389+
if ($TemplatePolicyName -and $TenantPolicyName -and $TemplatePolicyName -eq $TenantPolicyName) {
386390
$PolicyFound = $true
387391
break
388392
}

0 commit comments

Comments
 (0)