Skip to content

Commit 0879550

Browse files
author
Luis Mengel
committed
Fix false non-compliant drift detection for templates by handling empty values and nulls appropriately
1 parent 2bc6c54 commit 0879550

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

Modules/CIPPCore/Public/Compare-CIPPIntuneObject.ps1

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,29 +277,45 @@ function Compare-CIPPIntuneObject {
277277
($Object2 -is [Array] -or $Object2 -is [System.Collections.IList])) {
278278
continue
279279
}
280-
if ($Object1.$propName -and $Object2.$propName) {
281-
Compare-ObjectsRecursively -Object1 $Object1.$propName -Object2 $Object2.$propName -PropertyPath $newPath -Depth ($Depth + 1) -MaxDepth $MaxDepth
280+
$val1 = $Object1.$propName
281+
$val2 = $Object2.$propName
282+
$val1IsEmpty = ($null -eq $val1 -or $val1 -eq '' -or ($val1 -is [Array] -and $val1.Count -eq 0))
283+
$val2IsEmpty = ($null -eq $val2 -or $val2 -eq '' -or ($val2 -is [Array] -and $val2.Count -eq 0))
284+
if ($val1IsEmpty -and $val2IsEmpty) {
285+
# Both empty (null, "", []) - no difference
286+
continue
287+
}
288+
if ($val1 -or $val2) {
289+
Compare-ObjectsRecursively -Object1 $val1 -Object2 $val2 -PropertyPath $newPath -Depth ($Depth + 1) -MaxDepth $MaxDepth
282290
}
283291
} catch {
284292
throw
285293
}
286294
} elseif ($prop1Exists) {
287295
try {
288-
$result.Add([PSCustomObject]@{
296+
$val = $Object1.$propName
297+
$valIsEmpty = ($null -eq $val -or $val -eq '' -or ($val -is [Array] -and $val.Count -eq 0))
298+
if (-not $valIsEmpty) {
299+
$result.Add([PSCustomObject]@{
289300
Property = $newPath
290-
ExpectedValue = $Object1.$propName
301+
ExpectedValue = $val
291302
ReceivedValue = ''
292303
})
304+
}
293305
} catch {
294306
throw
295307
}
296308
} else {
297309
try {
298-
$result.Add([PSCustomObject]@{
310+
$val = $Object2.$propName
311+
$valIsEmpty = ($null -eq $val -or $val -eq '' -or ($val -is [Array] -and $val.Count -eq 0))
312+
if (-not $valIsEmpty) {
313+
$result.Add([PSCustomObject]@{
299314
Property = $newPath
300315
ExpectedValue = ''
301-
ReceivedValue = $Object2.$propName
316+
ReceivedValue = $val
302317
})
318+
}
303319
} catch {
304320
throw
305321
}

0 commit comments

Comments
 (0)