Creating a DSC Configuration Template

During the recent TechEd in Houston, there was a lot of talk and excitement about Desired State Configuration, or DSC. I’m not going to cover DSC itself here but rather address a minor issue for those of you just getting started. When you build a configuration, how can your figure out what resource settings to use?

To start with, you can look use the Get-DSCResource cmdlet which will list all resources in the default locations.

get-dscresource

The properties for each resource are also there, although you have to dig a little.

get-dscresourceproperties

From the screen shot you can see which properties are mandatory and the possible values for the rest. The Get-DSCResource cmdlet will even take this a step further and show you the complete syntax on how to use a particular resource.

get-dscresourcesyntax

To build a configuration, you can copy, paste and edit. But I wanted more, as I often do when it comes to things PowerShell. So I wrote a function called New-DSCConfigurationTemplate that will generate a complete configuration with as many resources as you have available.

The function will create a configuration template with whatever resources you specify.
new-dscconfig01
By default the function writes to the pipeline, but you can specify a file name and even open the file in the ISE. Here’s how to create a single template for all DSC resources on your computer.

new-dscconfig02
Mandatory properties are preceded by a *, which you need to delete. Properties have all of the possible values or at the very least what type of value you need to enter. Simply delete what you don’t want and in no time you have a complete DSC configuration! Don’t forget to substitute a name in for without the <>.

I wrote this with the assumption that I could run this once to create a template, then copy and paste what I need into a new configuration. Another option would be to create ISE snippets for these resources.

Personally, anything that saves me typing is a great help. I hope you’ll let me know what you think.

3 thoughts on “Creating a DSC Configuration Template

  1. Thanks for posting this. I’m really impressed with how many people are publishing so much good content about DSC.

    Also…it was good to meet you in person at TechEd last week!

Comments are closed.