Get-Content in ConfigurationData

This topic contains 2 replies, has 2 voices, and was last updated by  Alexander Johansson 3 weeks, 4 days ago.

  • Author
  • #101284

    Alexander Johansson


    I have a ConfigurationData psd1-file.
    Inside this file I'm trying to use Get-Content, this because I have an XML-file which contains configuration for a specific component, and I want changes in this file to be documented in our source code repository/a new MOF-file to be compiled when changes are made to it, to get the configuration pushed out when changes are made to this file. Maybe there's a better way?

    However, when I'm trying to compile my MOF-file, I receive the following error:

    Error: The command 'Get-Content' is not allowed in restricted language mode or a Data section.

    This is what the code block looks like in my ConfigurationData:

        AppConfiguration = @{
            XmlContent = (Get-Content -Path '.\XmlContent.xml')

    Am I not be supposed to be able to use Get-Content in my ConfigurationData, or am I missing something in my code?
    I can see that in some examples from Microsoft, they are using this approach in the same way as I'm trying to implement it, so the error I receive is, as you can understand, for me somewhat unexpected.

    Your input is, as always, much appreciated.

  • #101295


    Indeed, get-content is not allowed inside a psd1, but you don't have to build your Configuration Data hashtable from PSD1, you can use a ps1 instead.

    # CompileMof.ps1
    $ConfigurationData = @{
      AllNodes = @(
        Nodename = 'SRV01'
      AppConfiguration = (GC -raw myfile.xml)
    Configuration MyDscConfig {
    # ... your config here
    MyDscConfig -ConfigurationData $ConfigurationData -Out C:\
    • #101301

      Alexander Johansson

      Does this mean that I need to have my DSC configuration and configuration data in the same file?
      I tried to rename my ConfigurationData.psd1 to .ps1, but then I get the following error:

      Error: Cannot process argument transformation on parameter 'ConfigurationData'. Cannot resolve the path '.\ConfigurationData.ps1' to a single .psd1 file.

You must be logged in to reply to this topic.