Skip to content

Commit f02f80d

Browse files
add short circuit for datetimes and other potential nested objects.
1 parent 39ab54e commit f02f80d

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

Modules/CIPPCore/Public/Compare-CIPPIntuneObject.ps1

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,16 @@ function Compare-CIPPIntuneObject {
4444

4545
function Compare-ObjectsRecursively {
4646
param (
47-
[Parameter(Mandatory = $true)] $Object1,
48-
[Parameter(Mandatory = $true)] $Object2,
49-
[Parameter(Mandatory = $false)] [string]$PropertyPath = '',
47+
[Parameter(Mandatory = $true)]
48+
$Object1,
49+
50+
[Parameter(Mandatory = $true)]
51+
$Object2,
52+
53+
[Parameter(Mandatory = $false)]
54+
[string]$PropertyPath = '',
5055
[int]$Depth = 0,
51-
[int]$MaxDepth = 15
56+
[int]$MaxDepth = 20
5257
)
5358

5459
if ($Depth -ge $MaxDepth) {
@@ -82,6 +87,21 @@ function Compare-CIPPIntuneObject {
8287
return
8388
}
8489

90+
# Short-circuit recursion for primitive types
91+
$primitiveTypes = @([double], [decimal], [datetime], [timespan], [guid] )
92+
foreach ($type in $primitiveTypes) {
93+
if ($Object1 -is $type -and $Object2 -is $type) {
94+
if ($Object1 -ne $Object2) {
95+
$result.Add([PSCustomObject]@{
96+
Property = $PropertyPath
97+
ExpectedValue = $Object1
98+
ReceivedValue = $Object2
99+
})
100+
}
101+
return
102+
}
103+
}
104+
85105
if ($Object1 -is [System.Collections.IDictionary]) {
86106
$allKeys = @($Object1.Keys) + @($Object2.Keys) | Select-Object -Unique
87107

@@ -197,6 +217,7 @@ function Compare-CIPPIntuneObject {
197217
} else {
198218
$intuneCollection = Get-Content .\intuneCollection.json | ConvertFrom-Json -ErrorAction SilentlyContinue
199219

220+
# Process reference object settings
200221
$referenceItems = $ReferenceObject.settings | ForEach-Object {
201222
$settingInstance = $_.settingInstance
202223
$intuneObj = $intuneCollection | Where-Object { $_.id -eq $settingInstance.settingDefinitionId }
@@ -223,6 +244,8 @@ function Compare-CIPPIntuneObject {
223244
$child.choiceSettingValue.value
224245
}
225246
}
247+
248+
# Add object to our temporary list
226249
[PSCustomObject]@{
227250
Key = "GroupChild-$($child.settingDefinitionId)"
228251
Label = $childLabel
@@ -288,6 +311,7 @@ function Compare-CIPPIntuneObject {
288311
$tempOutput
289312
}
290313

314+
# Process difference object settings
291315
$differenceItems = $DifferenceObject.settings | ForEach-Object {
292316
$settingInstance = $_.settingInstance
293317
$intuneObj = $intuneCollection | Where-Object { $_.id -eq $settingInstance.settingDefinitionId }
@@ -314,6 +338,8 @@ function Compare-CIPPIntuneObject {
314338
$child.choiceSettingValue.value
315339
}
316340
}
341+
342+
# Add object to our temporary list
317343
[PSCustomObject]@{
318344
Key = "GroupChild-$($child.settingDefinitionId)"
319345
Label = $childLabel

0 commit comments

Comments
 (0)