powershelldsc

Is there a way to reference a parameter value within the same PSD1 file?


Let's say that I have a PSD1 file, with the following code:

@{
    AllNodes = @(
    @{
        NodeName = $env:COMPUTERNAME
        Tags = @{
            Environment = "dev"
            Datacenter = "east 1"
        }
        Data = @{
            ConfigName = [Tags.Environment]-[Tags.Datacenter.replace(" ","-")]
        }
    })
}

See how I am trying to reference the "Tags" section later on in the same file? Is there some way to do that, or do I simply need to do so within a separate PS1 file?


Solution

  • As iRon points out, what you're trying to do is not supported (and, if it were, would pose implementation challenges - see bottom section).

    In the interest of security (preventing injection of unwanted code and data), PowerShell strictly limits what is permitted inside a *.psd1 file:

    Note: *.psd1 files are used in the following contexts:


    As for your idea:

    Hypothetically allowing intra-hashtable cross-references:

    If you feel strongly enough about having such a feature, I encourage you to submit a feature request on GitHub.