Skip to content

Commit

Permalink
Merge pull request #3184 from NikCharlebois/FixForNameExtraction
Browse files Browse the repository at this point in the history
Ensures no resource instance have the same name when extracting them.
  • Loading branch information
ykuijs authored Apr 19, 2023
2 parents ab4bef8 + 275b337 commit 5d890f3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 extraction could still have duplicates.

# 1.23.412.1

Expand Down
20 changes: 20 additions & 0 deletions Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -1308,6 +1311,9 @@ function Export-M365DSCConfiguration
-AllComponents `
-Filters $Filters
}

# Clear the exported resource instances' names Global variable
$Global:M365DSCExportedResourceInstancesNames = $null
}

$Script:M365DSCDependenciesValidated = $false
Expand Down Expand Up @@ -3230,6 +3236,19 @@ 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 ($null -ne $Global:M365DSCExportedResourceInstancesNames -and `
$Global:M365DSCExportedResourceInstancesNames.Contains($tempName))
{
$tempName = $instanceName + "-" + $i.ToString()
$i++
}
$instanceName = $tempName
$Global:M365DSCExportedResourceInstancesNames += $tempName

$content = " $ResourceName `"$instanceName`"`r`n"
$content += " {`r`n"
$partialContent = Get-DSCBlock -Params $Results -ModulePath $ModulePath
Expand Down Expand Up @@ -3286,6 +3305,7 @@ function Get-M365DSCExportContentForResource
}
$content += $partialContent
$content += " }`r`n"

return $content
}

Expand Down

0 comments on commit 5d890f3

Please sign in to comment.