Skip to content

ReverseDSC.Core.psm1->Add-ConfigurationDataEntry doesn't reset $ConfigurationDataContent #46

@dcreeronbemo

Description

@dcreeronbemo

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:

  1. $ConfigurationDataContent is only initialized to empty one time at the script level [$ConfigurationDataContent = @{}].

  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions