Skip to content

Commit

Permalink
Reimplement fallback for endless loop
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienTschanz committed Sep 17, 2024
1 parent b99c11b commit 1d0aedf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
17 changes: 15 additions & 2 deletions Modules/Microsoft365DSC/Modules/M365DSCDRGUtil.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2327,6 +2327,7 @@ function Export-IntuneSettingCatalogPolicySettings
else
{
$skip = 0
$breakCounter = 0
$newSettingName = $settingName
do {
$previousSettingName = $newSettingName
Expand All @@ -2342,9 +2343,21 @@ function Export-IntuneSettingCatalogPolicySettings
}
$settingsWithSameName = $combinationMatchesWithOffsetUri
$skip++
} while ($combinationMatchesWithOffsetUri.Count -gt 1)
$breakCounter++
} while ($combinationMatchesWithOffsetUri.Count -gt 1 -and $breakCounter -lt 8)

$settingName = $newSettingName
if ($breakCounter -lt 8)
{
$settingName = $newSettingName
}
else
{
# Alternative way if no unique setting name can be found
$parentSettingIdProperty = $parentSetting.Id.Split('_')[-1]
$parentSettingIdWithoutProperty = $parentSetting.Id.Replace("_$parentSettingIdProperty", "")
# We can't use the entire setting here, because the child setting id does not have to come after the parent setting id
$settingName = $settingDefinition.Id.Replace($parentSettingIdWithoutProperty + "_", "").Replace($parentSettingIdProperty + "_", "")
}
}
}

Expand Down
17 changes: 15 additions & 2 deletions ResourceGenerator/M365DSCResourceGenerator.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -3816,6 +3816,7 @@ function New-SettingsCatalogSettingDefinitionSettingsFromTemplate {
else
{
$skip = 0
$breakCounter = 0
$newSettingName = $settingName
do {
$previousSettingName = $newSettingName
Expand All @@ -3831,9 +3832,21 @@ function New-SettingsCatalogSettingDefinitionSettingsFromTemplate {
}
$settingsWithSameName = $combinationMatchesWithOffsetUri
$skip++
} while ($combinationMatchesWithOffsetUri.Count -gt 1)
$breakCounter++
} while ($combinationMatchesWithOffsetUri.Count -gt 1 -and $breakCounter -lt 8)

$settingName = $newSettingName
if ($breakCounter -lt 8)
{
$settingName = $newSettingName
}
else
{
# Alternative way if no unique setting name can be found
$parentSettingIdProperty = $parentSetting.Id.Split('_')[-1]
$parentSettingIdWithoutProperty = $parentSetting.Id.Replace("_$parentSettingIdProperty", "")
# We can't use the entire setting here, because the child setting id does not have to come after the parent setting id
$settingName = $settingDefinition.Id.Replace($parentSettingIdWithoutProperty + "_", "").Replace($parentSettingIdProperty + "_", "")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
@{
Id = 'device_vendor_msft_defender_configuration_devicecontrol_policyrules_{ruleid}_ruledata_id'
Name = 'Id'
OffsetUri = '/configuration/devicecontrol/policyrules/{0}/ruledata'
AdditionalProperties = @{
'@odata.type' = '#microsoft.graph.deviceManagementConfigurationSimpleSettingDefinition'
dependentOn = @(
Expand Down Expand Up @@ -353,6 +354,7 @@ Describe -Name $Global:DscHelper.DescribeHeader -Fixture {
@{
Id = 'device_vendor_msft_defender_configuration_devicecontrol_policyrules_{ruleid}_ruledata_entry_id'
Name = 'Id'
OffsetUri = '/configuration/devicecontrol/policyrules/{0}/ruledata'
AdditionalProperties = @{
'@odata.type' = '#microsoft.graph.deviceManagementConfigurationSimpleSettingDefinition'
dependentOn = @(
Expand Down

0 comments on commit 1d0aedf

Please sign in to comment.