From 3ad2b4a957bbe051c6129f8c93f062c22c02b59a Mon Sep 17 00:00:00 2001 From: Fabien Tschanz Date: Sat, 13 Jul 2024 14:22:36 +0200 Subject: [PATCH] Fix array comparison in report --- CHANGELOG.md | 6 +++++ .../Modules/M365DSCReport.psm1 | 23 ++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f62077cf2..732f797877 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change log for Microsoft365DSC +# UNRELEASED + +* M365DSCReport + * Fixes an issue where the comparison treats empty arrays as an empty string. + FIXES [#4796](https://github.com/microsoft/Microsoft365DSC/issues/4796) + # 1.24.710.3 * MISC diff --git a/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 index a92596eb70..a005f23ee7 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 @@ -794,11 +794,7 @@ function Compare-M365DSCConfigurations { if ($propertyName -notin $filteredProperties) { - $destinationPropertyName = $destinationResource.Keys | Where-Object -FilterScript { $_ -eq $propertyName } - if ([System.String]::IsNullOrEmpty($destinationPropertyName)) - { - $destinationPropertyName = $propertyName - } + $destinationPropertyName = $propertyName # Case where the property contains CIMInstances if ($null -ne $sourceResource.$propertyName.Keys -and $sourceResource.$propertyName.Keys.Contains('CIMInstance')) @@ -892,7 +888,7 @@ function Compare-M365DSCConfigurations } # Needs to be a separate nested if statement otherwise the ReferenceObject can be null and it will error out; elseif ($destinationResource.ContainsKey($destinationPropertyName) -eq $false -or (-not [System.String]::IsNullOrEmpty($propertyName) -and - (-not [System.String]::IsNullOrEmpty($sourceResource.$propertyName) -and + ($null -ne $sourceResource.$propertyName -and $null -ne (Compare-Object -ReferenceObject ($sourceResource.$propertyName)` -DifferenceObject ($destinationResource.$destinationPropertyName)))) -and -not ([System.String]::IsNullOrEmpty($destinationResource.$destinationPropertyName) -and [System.String]::IsNullOrEmpty($sourceResource.$propertyName))) @@ -952,11 +948,8 @@ function Compare-M365DSCConfigurations { if ($propertyName -notin $filteredProperties) { - $sourcePropertyName = $destinationResource.Keys | Where-Object -FilterScript { $_ -eq $propertyName } - if ([System.String]::IsNullOrEmpty($sourcePropertyName)) - { - $sourcePropertyName = $propertyName - } + $sourcePropertyName = $propertyName + # Case where the property contains CIMInstances if ($null -ne $destinationResource.$propertyName.Keys -and $destinationResource.$propertyName.Keys.Contains('CIMInstance')) { @@ -979,13 +972,15 @@ function Compare-M365DSCConfigurations foreach ($property in $instance.Keys) { if ($null -eq $sourceResourceInstance."$property" -or ` - (-not [System.String]::IsNullOrEmpty($instance."$property") -and ` + ($null -ne $instance."$property" -and ` $null -ne (Compare-Object -ReferenceObject ($instance."$property")` -DifferenceObject ($sourceResourceInstance."$property")))) { # Make sure we haven't already added this drift in the delta return object to prevent duplicates. - $existing = $delta | Where-Object -FilterScript {$_.ResourceName -eq $destinationResource.ResourceName -and ` - $_.ResourceInstanceName -eq $destinationResource.ResourceInstanceName} + $existing = $delta | Where-Object -FilterScript { + $_.ResourceName -eq $destinationResource.ResourceName -and + $_.ResourceInstanceName -eq $destinationResource.ResourceInstanceName + } $sameEntry = $null if ($null -ne $existing)