Author Posts

May 28, 2018 at 8:56 am

Hi,

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.

May 28, 2018 at 12:51 pm

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:\

May 28, 2018 at 1:36 pm

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.