Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensures no resource instance have the same name when extracting them. #3184

Merged
merged 3 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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