-
Notifications
You must be signed in to change notification settings - Fork 45
Description
We're trying to use Microsoft365DSC and Export-M365DSCConfiguration which uses ReverseDSC.Core.psm1 to create the ConfigurationData.psd1 file.
Our export script is used to test exporting different M365DSC components using the AccessTokens parameter for authentication. We need to run different scenarios for Exchange Online and Graph components.
If we run our PowerShell Export script multiple times in a single PowerShell console window the ConfigurationData.psd1 isn't properly updated with the current AccessToken value; it ends up using whatever the previous entry value was as there's no reset/clear happening between runs.
We've tracked this down to the following issues:
-
$ConfigurationDataContent is only initialized to empty one time at the script level [$ConfigurationDataContent = @{}].
-
The Add-ConfigurationDataEntry function doesn't update existing Key/Value entries, it only adds new entries.
If we change the code to update existing entries, like below, then the ConfigurationData.psd1 AccessTokens is correctly updated on repeated runs of the script in a single PowerShell console:
if (!$ConfigurationDataContent[$Node].Entries.ContainsKey($Key))
{
$ConfigurationDataContent[$Node].Entries.Add($Key, @{Value = $Value; Description = $Description })
}
else {
$existingEntry = $ConfigurationDataContent[$Node].Entries[$Key]
$existingEntry.Value = $Value
$existingEntry.Description = $Description
}
We'd like some feedback about the best way to ensure that $ConfigurationDataContent is reset and/or update on successive/subsequent runs of a script, in the same PowerShell console, that ends up using ReverseDSC.Core.psm1.
Thanks.