diff --git a/CHANGELOG.md b/CHANGELOG.md index 12f2690310..05ac69bfce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ * MISC * M365DSCDRGUtil Add new parameter for customizable assignment identifier + * M365DSCUtil + Change heuristics on how to find the mandatory key of the resources to + include them as part of the ResourceInstanceName during their export + FIXES [#4333](https://github.com/microsoft/Microsoft365DSC/issues/4333) # 1.24.221.1 @@ -85,8 +89,8 @@ * AADConditionalAccessPolicy * Removed invalid empty string value that was added to the validate set of two parameters. - * Updated permission reference for app-onlzy authentication. - FIXES [[#3329](https://github.com/microsoft/Microsoft365DSC/issues/3329)] + * Updated permission reference for app-only authentication. + FIXES [#3329](https://github.com/microsoft/Microsoft365DSC/issues/3329) * AADRoleEligibilityScheduleRequest * Fixed an issue where an error was thrown if no requests were found instead of simply returning the Null object. @@ -94,8 +98,9 @@ * Fix handling of DisplayName property in comparison FIXES [#4019](https://github.com/microsoft/Microsoft365DSC/issues/4019) * AADUser - * Fixed and issue where an user would be created even if the resrouce was set to absent. - FIXES [[#4265](https://github.com/microsoft/Microsoft365DSC/issues/4265)] + * Fixed and issue where an user would be created even if the resource was set + to absent. + FIXES [#4265](https://github.com/microsoft/Microsoft365DSC/issues/4265) * EXOMobileDeviceMailboxPolicy * Fixes an issue where an empty MinPasswordLength value was always passed down to the update logic flow. diff --git a/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 index 1dca1435e2..9fa3c31b6d 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 @@ -3361,38 +3361,47 @@ function Get-M365DSCExportContentForResource $Results = Format-M365DSCString -Properties $Results ` -ResourceName $ResourceName + if ($Script:AllM365DscResources.Count -eq 0) + { + $Script:AllM365DscResources = Get-DscResource -Module 'Microsoft365Dsc' + } + $primaryKey = '' - if ($Results.ContainsKey('IsSingleInstance')) + $Resource = $Script:AllM365DscResources.Where({ $_.Name -eq $ResourceName }) + $Keys = $Resource.Properties.Where({ $_.IsMandatory }) | ` + Select-Object -ExpandProperty Name + if ($Keys.Contains('IsSingleInstance')) { $primaryKey = '' } - elseif ($Results.ContainsKey('DisplayName')) + elseif ($Keys.Contains('DisplayName')) { $primaryKey = $Results.DisplayName } - elseif ($Results.ContainsKey('Identity')) - { - $primaryKey = $Results.Identity - } - elseif ($Results.ContainsKey('Id')) - { - $primaryKey = $Results.Id - } - elseif ($Results.ContainsKey('Name')) + elseif ($Keys.Contains('Name')) { $primaryKey = $Results.Name } - elseif ($Results.ContainsKey('Title')) + elseif ($Keys.Contains('Title')) { $primaryKey = $Results.Title } - elseif ($Results.ContainsKey('CdnType')) + elseif ($Keys.Contains('Identity')) + { + $primaryKey = $Results.Identity + } + elseif ($Keys.Contains('Id')) { - $primaryKey = $Results.CdnType + $primaryKey = $Results.Id } - elseif ($Results.ContainsKey('Usage')) + + if ([String]::IsNullOrEmpty($primaryKey) -and ` + -not $Keys.Contains('IsSingleInstance')) { - $primaryKey = $Results.Usage + foreach ($Key in $Keys) + { + $primaryKey += $Results.$Key + } } $instanceName = $ResourceName