From 1d0aedf44269d53381726a5e37b70b220be228d5 Mon Sep 17 00:00:00 2001 From: Fabien Tschanz Date: Tue, 17 Sep 2024 21:42:35 +0200 Subject: [PATCH] Reimplement fallback for endless loop --- .../Microsoft365DSC/Modules/M365DSCDRGUtil.psm1 | 17 +++++++++++++++-- ResourceGenerator/M365DSCResourceGenerator.psm1 | 17 +++++++++++++++-- ...IntuneDeviceControlPolicyWindows10.Tests.ps1 | 2 ++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Modules/Microsoft365DSC/Modules/M365DSCDRGUtil.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCDRGUtil.psm1 index 68d95b87d0..542a206b3d 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCDRGUtil.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCDRGUtil.psm1 @@ -2327,6 +2327,7 @@ function Export-IntuneSettingCatalogPolicySettings else { $skip = 0 + $breakCounter = 0 $newSettingName = $settingName do { $previousSettingName = $newSettingName @@ -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 + "_", "") + } } } diff --git a/ResourceGenerator/M365DSCResourceGenerator.psm1 b/ResourceGenerator/M365DSCResourceGenerator.psm1 index 23560cbd98..ecdccf6a86 100644 --- a/ResourceGenerator/M365DSCResourceGenerator.psm1 +++ b/ResourceGenerator/M365DSCResourceGenerator.psm1 @@ -3816,6 +3816,7 @@ function New-SettingsCatalogSettingDefinitionSettingsFromTemplate { else { $skip = 0 + $breakCounter = 0 $newSettingName = $settingName do { $previousSettingName = $newSettingName @@ -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 + "_", "") + } } } diff --git a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.IntuneDeviceControlPolicyWindows10.Tests.ps1 b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.IntuneDeviceControlPolicyWindows10.Tests.ps1 index 31712d60ea..efe2f33002 100644 --- a/Tests/Unit/Microsoft365DSC/Microsoft365DSC.IntuneDeviceControlPolicyWindows10.Tests.ps1 +++ b/Tests/Unit/Microsoft365DSC/Microsoft365DSC.IntuneDeviceControlPolicyWindows10.Tests.ps1 @@ -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 = @( @@ -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 = @(