Skip to content

Commit

Permalink
Merge pull request #5463 from FabienTschanz/feat/string-comparison-im…
Browse files Browse the repository at this point in the history
…provements

Add separate check for strings
  • Loading branch information
ykuijs authored Nov 28, 2024
2 parents 811e230 + 2e5ba30 commit e19a2ac
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

* IntuneTrustedRootCertificateIOS
* Initial release
* M365DSCDRGUtil
* Add separate check for strings with ordinal comparison and standardized line breaks.
* M365DSCUtil
* Add separate check for strings with ordinal comparison and standardized line breaks.

# 1.24.1127.1

Expand Down
68 changes: 59 additions & 9 deletions Modules/Microsoft365DSC/Modules/M365DSCDRGUtil.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ function Compare-M365DSCComplexObject
{
if ($Source.Length -ne $Target.Length)
{
Write-Verbose -Message "Configuration drift - The complex array have different number of items: Source {$($Source.Length)} Target {$($Target.Length)}"
Write-Verbose -Message "Configuration drift - The complex array have different number of items: Source {$($Source.Length)}, Target {$($Target.Length)}"
return $false
}
if ($Source.Length -eq 0)
Expand All @@ -627,7 +627,9 @@ function Compare-M365DSCComplexObject

if (-not $compareResult)
{
Write-Verbose -Message "Configuration drift - Intune Policy Assignment: $key Source {$Source} Target {$Target}"
Write-Verbose -Message "Configuration drift - Intune Policy Assignment: $key"
Write-Verbose -Message "Source {$Source}"
Write-Verbose -Message "Target {$Target}"
return $false
}

Expand Down Expand Up @@ -724,7 +726,9 @@ function Compare-M365DSCComplexObject
$targetValue = 'null'
}

Write-Verbose -Message "Configuration drift - key: $key Source {$sourceValue} Target {$targetValue}"
Write-Verbose -Message "Configuration drift - key: $key"
Write-Verbose -Message "Source {$sourceValue}"
Write-Verbose -Message "Target {$targetValue}"
return $false
}

Expand Down Expand Up @@ -753,7 +757,9 @@ function Compare-M365DSCComplexObject

if (-not $compareResult)
{
Write-Verbose -Message "Configuration drift - complex object key: $key Source {$sourceValue} Target {$targetValue}"
Write-Verbose -Message "Configuration drift - complex object key: $key"
Write-Verbose -Message "Source {$sourceValue}"
Write-Verbose -Message "Target {$targetValue}"
return $false
}
}
Expand All @@ -774,6 +780,26 @@ function Compare-M365DSCComplexObject
$compareResult = $null
}
}
elseif ($targetType -eq 'String')
{
# Align line breaks
if (-not [System.String]::IsNullOrEmpty($referenceObject))
{
$referenceObject = $referenceObject.Replace("`r`n", "`n")
}

if (-not [System.String]::IsNullOrEmpty($differenceObject))
{
$differenceObject = $differenceObject.Replace("`r`n", "`n")
}

$compareResult = $true
$ordinalComparison = [System.String]::Equals($referenceObject, $differenceObject, [System.StringComparison]::Ordinal)
if ($ordinalComparison)
{
$compareResult = $null
}
}
else
{
$compareResult = Compare-Object `
Expand All @@ -783,7 +809,9 @@ function Compare-M365DSCComplexObject

if ($null -ne $compareResult)
{
Write-Verbose -Message "Configuration drift - simple object key: $key Source {$sourceValue} Target {$targetValue}"
Write-Verbose -Message "Configuration drift - simple object key: $key"
Write-Verbose -Message "Source {$sourceValue}"
Write-Verbose -Message "Target {$targetValue}"
return $false
}
}
Expand Down Expand Up @@ -2321,7 +2349,15 @@ function Export-IntuneSettingCatalogPolicySettings
{
'#microsoft.graph.deviceManagementConfigurationSimpleSettingInstance'
{
$settingValue = if ($IsRoot) { $SettingInstance.AdditionalProperties.simpleSettingValue.value } else { $SettingInstance.simpleSettingValue.value }
$simpleSetting = if ($IsRoot) { $SettingInstance.AdditionalProperties.simpleSettingValue } else { $SettingInstance.simpleSettingValue }
if ($simpleSetting.'@odata.type' -eq '#microsoft.graph.deviceManagementConfigurationIntegerSettingValue')
{
$settingValue = [int]$simpleSetting.value
}
else
{
$settingValue = $simpleSetting.value
}
}
'#microsoft.graph.deviceManagementConfigurationChoiceSettingInstance'
{
Expand Down Expand Up @@ -2411,16 +2447,30 @@ function Export-IntuneSettingCatalogPolicySettings
'#microsoft.graph.deviceManagementConfigurationSimpleSettingCollectionInstance'
{
$values = @()
$childValues = if ($IsRoot) { $SettingInstance.AdditionalProperties.simpleSettingCollectionValue.value } else { $SettingInstance.simpleSettingCollectionValue.value }
$childValues = if ($IsRoot) { $SettingInstance.AdditionalProperties.simpleSettingCollectionValue } else { $SettingInstance.simpleSettingCollectionValue }
foreach ($value in $childValues)
{
$values += $value
if ($value.'@odata.type' -eq '#microsoft.graph.deviceManagementConfigurationIntegerSettingValue')
{
$values += [int]$value.value
}
else
{
$values += $value.value
}
}
$settingValue = $values
}
Default
{
$settingValue = $SettingInstance.value
if ($SettingInstance.'@odata.type' -eq '#microsoft.graph.deviceManagementConfigurationIntegerSettingValue')
{
$settingValue += [int]$SettingInstance.value
}
else
{
$settingValue = $SettingInstance.value
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ function Test-M365DSCParameterState
[System.Collections.Hashtable]
$IncludedDrifts
)

$VerbosePreference = 'SilentlyContinue'
#region Telemetry
$data = [System.Collections.Generic.Dictionary[[String], [String]]]::new()
Expand Down Expand Up @@ -842,6 +843,14 @@ function Test-M365DSCParameterState
-and [string]::IsNullOrEmpty($DesiredValues.$fieldName))
{
}
# Align line breaks
elseif (-not [string]::IsNullOrEmpty($CurrentValues.$fieldName) `
-and -not [string]::IsNullOrEmpty($DesiredValues.$fieldName) `
-and [string]::Equals($CurrentValues.$fieldName.Replace("`r`n", "`n"), `
$DesiredValues.$fieldName.Replace("`r`n", "`n"), `
[System.StringComparison]::Ordinal))
{
}
else
{
Write-Verbose -Message ('String value for property ' + `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
}

Mock -CommandName Get-PnPPropertyBag -MockWith {
return @(
@{
Key = 'MyKey'
Value = 'MyValue'
}
)
'MyValue'
}
}

Expand Down

0 comments on commit e19a2ac

Please sign in to comment.