diff --git a/CHANGELOG.md b/CHANGELOG.md index 7379c7b233..43ab87225b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change log for Microsoft365DSC +# UNRELEASED + +* MISC + * Updated logic for drift detection to be case insensitive. + FIXES [#2873](https://github.com/microsoft/Microsoft365DSC/issues/2873) + # 1.23.301.1 * IntuneDeviceEnrollmentConfigurationWindows10 diff --git a/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 index a3a8c6a37a..b5be884742 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 @@ -548,10 +548,17 @@ function Compare-M365DSCConfigurations { if ($propertyName -notin $filteredProperties) { + $destinationPropertyName = $destinationResource.Keys | Where-Object -FilterScript {$_ -eq $propertyName} + if ([System.String]::IsNullOrEmpty($destinationPropertyName)) + { + $destinationPropertyName = $propertyName + } + # Needs to be a separate nested if statement otherwise the ReferenceObject an be null and it will error out; - if ($destinationResource.ContainsKey($propertyName) -eq $false -or (-not [System.String]::IsNullOrEmpty($propertyName) -and - $null -ne (Compare-Object -ReferenceObject ($sourceResource.$propertyName)` - -DifferenceObject ($destinationResource.$propertyName)))) + if ($destinationResource.ContainsKey($destinationPropertyName) -eq $false -or (-not [System.String]::IsNullOrEmpty($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))) { if ($null -eq $drift) { @@ -562,13 +569,13 @@ function Compare-M365DSCConfigurations Properties = @(@{ ParameterName = $propertyName ValueInSource = $sourceResource.$propertyName - ValueInDestination = $destinationResource.$propertyName + ValueInDestination = $destinationResource.$destinationPropertyName }) } - if ($destinationResource.Contains("_metadata_$($propertyName)")) + if ($destinationResource.Contains("_metadata_$($destinationPropertyName)")) { - $Metadata = $destinationResource."_metadata_$($propertyName)" + $Metadata = $destinationResource."_metadata_$($destinationPropertyName)" $Level = $Metadata.Split('|')[0].Replace('### ', '') $Information = $Metadata.Split('|')[1] $drift.Properties[0].Add('_Metadata_Level', $Level) @@ -580,11 +587,11 @@ function Compare-M365DSCConfigurations $newDrift = @{ ParameterName = $propertyName ValueInSource = $sourceResource.$propertyName - ValueInDestination = $destinationResource.$propertyName + ValueInDestination = $destinationResource.$destinationPropertyName } - if ($destinationResource.Contains("_metadata_$($propertyName)")) + if ($destinationResource.Contains("_metadata_$($destinationPropertyName)")) { - $Metadata = $destinationResource."_metadata_$($propertyName)" + $Metadata = $destinationResource."_metadata_$($destinationPropertyName)" $Level = $Metadata.Split('|')[0].Replace('### ', '') $Information = $Metadata.Split('|')[1] $newDrift.Add('_Metadata_Level', $Level) @@ -602,8 +609,13 @@ function Compare-M365DSCConfigurations { if ($propertyName -notin $filteredProperties) { + $sourcePropertyName = $destinationResource.Keys | Where-Object -FilterScript {$_ -eq $propertyName} + if ([System.String]::IsNullOrEmpty($sourcePropertyName)) + { + $sourcePropertyName = $propertyName + } if (-not [System.String]::IsNullOrEmpty($propertyName) -and - -not $sourceResource.Contains($propertyName)) + -not $sourceResource.Contains($sourcePropertyName)) { if ($null -eq $drift) { @@ -612,7 +624,7 @@ function Compare-M365DSCConfigurations Key = $keyName KeyValue = $SourceKeyValue Properties = @(@{ - ParameterName = $propertyName + ParameterName = $sourcePropertyName ValueInSource = $null ValueInDestination = $destinationResource.$propertyName }) @@ -621,7 +633,7 @@ function Compare-M365DSCConfigurations else { $drift.Properties += @{ - ParameterName = $propertyName + ParameterName = $sourcePropertyName ValueInSource = $null ValueInDestination = $destinationResource.$propertyName } @@ -1128,7 +1140,9 @@ function New-M365DSCDeltaReport $cellStyle = "vertical-align:top;" } - if ($destinationValue.GetType().Name -eq 'Object[]' -and -not [System.String]::IsNullOrEmpty($CIMType)) + if (-not [System.String]::IsNullOrEmpty($destinationValue) -and + $destinationValue.GetType().Name -eq 'Object[]' -and + -not [System.String]::IsNullOrEmpty($CIMType)) { $destinationValue = "" $orderedKeys = $drift.ValueInDestination.Key | Sort-Object