Allowable DSC configuration content

DSC configuration data files follow the same restricted language set of rules that PowerShell data sections have. A PowerShell data section is a block of text that contains only data and a limited subset of the general PowerShell language.

The allowed code is limited to the following:

All PowerShell operators, with the exception of -match:

  • If, else, and elseIf statements.
  • The following automatic variables:
    • $PSCulture
    • $PSUICulture
    • $True
    • $False
    • $Null
    • Comments
    • Pipelines
  • Statements separated by semicolons.
  • Any cmdlets that you permit explicitly in a data section by using the SupportedCommand parameter.

This effectively means that there is little code you can put inside a DSC configuration data file by default. While this sounds like a bad limitation, in practice, it's a good thing as it prevents you from trying to put too much logic in what should be a data only file. Remember, every time we covered why you should be putting the decision-making logic inside DSC resources: it all applies here.

There is one case where you might want some small bits of code to be inside DSC configuration data files. Since we are dealing with environmental data, you may have different application configuration files, artifacts, or an installation file path to include in your data files depending on which environment or aspects of a target node you are operating on. Choosing which sets of data to include in your file may be something you need to do from time to time. For example, a production web server may have a different web.config file than the development web server, possibly in different locations as well. Keeping in mind the list we just covered, we will notice that we can't include cmdlet names inside the file. If this is the case, how can we use conditional logic?

The trick is in changing how we load the DSC configuration data file. We've already covered loading external data files by passing their path to the configuration function parameter ConfigurationData, and we can build on that to pass any configuration data we want.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset