microsoft / DSCParser

Allows the conversion of DSC scripts into PSObject for analysis purposes
MIT License
29 stars 21 forks source link

Resolve problem with variable name escape syntax #24 #25

Closed PrzemyslawKlys closed 2 years ago

PrzemyslawKlys commented 2 years ago

Consider this DSC

Configuration DSCExport
{
    $OrganizationName = $ConfigurationData.NonNodeData.OrganizationName
    Import-DscResource -ModuleName 'Microsoft365DSC' #-ModuleVersion '1.22.323.1'

    Node localhost
    {
        AADConditionalAccessPolicy 74ec9f84-045a-4e9c-846c-7875667a553a {
            ApplicationId = $ConfigurationData.NonNodeData.ApplicationId;
            DisplayName     = "All - Deny Basic authentication";
            BuiltInControls = @("mfa", $null, $ConfigurationData.NonNodeData.ApplicationSecret, 'Application');
        }
        SCLabelPolicy 99ef4d19-e250-4009-9a4e-70659fe2a34a {
            # This should be comment
            AdvancedSettings = @(
                # This should be comment
                MSFT_SCLabelSetting {
                    Key   = 'requiredowngradejustification'
                    Value = $ConfigurationData.NonNodeData.ApplicationSecret
                }
                MSFT_SCLabelSetting {
                    Key   = 'customurl'
                    Value = $true
                }
            );
            Credential       = $Credscredential;
            Ensure           = $true
            ExchangeLocation =$null
            Labels           = @("Confidential", $true, $null, "Internal");
            Name             = "Default Label Policy";
        }
    }
}
DSCExport -ConfigurationData .\ConfigurationData.psd1

When you use variables that use "variable name escape syntax" or "nested variables" or however else you call it - this DSC would break the objects and not be representative.

This PR fixes this for 3 cases:

I had to remove "dot" from noisy variables as it was impacting CimInstances not seeing dots at all.