From 0bb7e2876665dd5b5f5f9b84ca3a587ade7f2fba Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Wed, 19 Apr 2023 11:07:21 -0400 Subject: [PATCH 1/3] Ensures no resource instance have the same name when extracting them. --- CHANGELOG.md | 7 ++++--- .../Microsoft365DSC/Modules/M365DSCUtil.psm1 | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38834df6c1..3bc96ddc36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,17 +8,18 @@ * Initial release * IntuneDeviceConfigurationKioskPolicyWindows10 * Initial release +* SCLabelPolicy + * If label policy is set to None don't get its label display name since it's not required + FIXES [#3104](https://github.com/microsoft/Microsoft365DSC/issues/3104) * DRG * Fixed issue retrieving the cmdlet definition when the resource type is derived from an abstract type * Fixed issue with UnitTest and complex properties with AdditionalProperties * Fixed issue with Complex constructor and complex properties with AdditionalProperties -* SCLabelPolicy - * If label policy is set to None don't get its label display name since it's not required - FIXES [#3104](https://github.com/microsoft/Microsoft365DSC/issues/3104) * MISC * Reports will now exclude the authentication parameters (e.g., CertificateThumbprint, Credential, etc.). * Changed the Encoding helper's logic to ensure titled quotes and apostrophes are correctly evaluated. FIXES [#3165](https://github.com/microsoft/Microsoft365DSC/issues/3165) + * Fixes an issue where the new resource name extracton could still have duplicates. # 1.23.412.1 diff --git a/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 index fc9fed50ab..d8c3a1dbd0 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 @@ -1128,6 +1128,9 @@ function Export-M365DSCConfiguration $ManagedIdentity ) + # Define the exported resource instances' names Global variable + $Global:M365DSCExportedResourceInstancesNames = @() + # LaunchWebUI specified, launching that now if ($LaunchWebUI) { @@ -1308,6 +1311,9 @@ function Export-M365DSCConfiguration -AllComponents ` -Filters $Filters } + + # Clear the exported resource instances' names Global variable + $Global:M365DSCExportedResourceInstancesNames = $null } $Script:M365DSCDependenciesValidated = $false @@ -3230,6 +3236,18 @@ function Get-M365DSCExportContentForResource { $instanceName += "-$($Results.Workload)" } + + # Check to see if a resource with this exact name was already exported, if so, append a number to the end. + $i = 2 + $tempName = $instanceName + while ($Global:M365DSCExportedResourceInstancesNames.Contains("[$ResourceName]$tempName")) + { + $tempName = $instanceName + "-" + $i.ToString() + $i++ + } + $instanceName = $tempName + $Global:M365DSCExportedResourceInstancesNames += "[$ResourceName]$tempName" + $content = " $ResourceName `"$instanceName`"`r`n" $content += " {`r`n" $partialContent = Get-DSCBlock -Params $Results -ModulePath $ModulePath @@ -3286,6 +3304,7 @@ function Get-M365DSCExportContentForResource } $content += $partialContent $content += " }`r`n" + return $content } From 689dd238621ea20709707cefac315040edec58bf Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Wed, 19 Apr 2023 11:07:51 -0400 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bc96ddc36..26c7c85ccc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ * Reports will now exclude the authentication parameters (e.g., CertificateThumbprint, Credential, etc.). * Changed the Encoding helper's logic to ensure titled quotes and apostrophes are correctly evaluated. FIXES [#3165](https://github.com/microsoft/Microsoft365DSC/issues/3165) - * Fixes an issue where the new resource name extracton could still have duplicates. + * Fixes an issue where the new resource name extraction could still have duplicates. # 1.23.412.1 From 275b3379e9039945b2bf5dc1c07b4fd965189892 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Wed, 19 Apr 2023 11:51:01 -0400 Subject: [PATCH 3/3] Fixes --- Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 index d8c3a1dbd0..cd5ac7d57c 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 @@ -3240,13 +3240,14 @@ function Get-M365DSCExportContentForResource # Check to see if a resource with this exact name was already exported, if so, append a number to the end. $i = 2 $tempName = $instanceName - while ($Global:M365DSCExportedResourceInstancesNames.Contains("[$ResourceName]$tempName")) + while ($null -ne $Global:M365DSCExportedResourceInstancesNames -and ` + $Global:M365DSCExportedResourceInstancesNames.Contains($tempName)) { $tempName = $instanceName + "-" + $i.ToString() $i++ } $instanceName = $tempName - $Global:M365DSCExportedResourceInstancesNames += "[$ResourceName]$tempName" + $Global:M365DSCExportedResourceInstancesNames += $tempName $content = " $ResourceName `"$instanceName`"`r`n" $content += " {`r`n"