Using Community Desired State Configuration Resources

What we can accomplish with the provided resources for our Desired State Configuration is quite impressive, but when we start to consider some of the more complex settings we would like to start managing while leveraging this fantastic tool, we have really two options open to us:

  1. Roll our own resource provider
  2. Leverage some community-shared resource providers

Editor’s note: Need to catch up? Check out our previous articles in this series:

Community Resources

There are already a number of new resources available for us to add to our configuration shared by the community, a number of which can be located on the GITHUB account. Some of the current resources include:

  • GlobalAssemblyCache
  • CertificateStore
  • FirewallRule
  • NetworkAdapter
  • Pagefile
  • PowerPlan
  • SetExecutionPolicy
  • HostFile

How Do We Use Community DSC Resources?

Of course the community offerings are fantastic, but how do we use these resources in our configurations? The first step, of course, is to download them to your workstation (I will cover the correct way to do this using GIT in a following post, but for now just grab the precreated ZIP file, unblock it, and extract its content to your workspace. (Note: If you have downloaded this repository prior to Jan 23rd, 2014, due to UFT8 and folder hierarchy issues you must grab a newer copy)

When the download and extraction is complete, I have a new structure on my X:\ drive, with a folder for PowerShell, and within it a folder to host my copy of the repository called Repos. Within this folder, I then extracted the content of the into a folder called For reference, this is what my results looks like.

Community Desired State Configuration Resources PowerShell folders

PowerShell Modules – Or Not!

With the resources now happily located on our working folder, as with any other PowerShell scripts or modules we will work with we need to be able to reference them (in this case as part of our Configuration statements).

To achieve this, each resource is actually packed as a PowerShell module, but these are not normal modules that we can import with the trusty ol’ Import-Module command. In this case ,we have a set of two new commands available to use, but first, let’s get the environment ready.

The first step is quite simple – we just need to add our new repository to our PowerShell module path. Referencing my folder structure above I will be pointing to Resources folder.

$env:PSModulePath = $env:PSModulePath + ";X:\PowerShell\Repos\\Resources"

Now, we should be able to discover the new resources available to leverage in our configurations. To enumerate these, we will use the new commandlet Get-DSCResources, which will scan the PowerShell modules folders to see if the contained modules are for DSC. (Note: If you really want to see this working, then run the command using the –verbose option.)

Community Desired State Configuration Resources DSC

Importing the Resources

Assuming everything has worked correctly, the results of your discovery for DSC resources should yield a nice list for you, including the new offerings from the community repository we just referenced. All that remains now is to leverage these in our configuration.

This is actually quite easy; if you have been following along, we have already covered this part of the procedure when we used DSC to configure our pull server. (But due to the low number of comments on that post, I guess not many of you actually tried it! Hold your heads in shame for 30 seconds please!)

In the list of modules we imported you should notice that one is called cPSDesiredStateConfiguration, which is the same module – just somewhat fixed and named to match the requested naming convention as MS originally requested for such a scenario.

To use any of these resource in our configuration, given that we can enumerate them using Get-DSCResource, we can now also use in our configuration the associated Import-DSCResource command to load up the resource. As an example, we would change our original configuration for setting up the DSC pull server using DSC to now use the new version of the module available to us by changing just one single line.

Configuration Assert_DSCWebService
  param (
    [String] $certificateThumbprint

  Import-DSCResource -ModuleName xPSDesiredStateConfiguration
  Import-DSCResource -ModuleName cPSDesiredStateConfiguration

  Node localhost
    WindowsFeature DSCServiceFeature
      Ensure = "Present"
      Name = "DSC-Service"

Once the resource is imported, the rest will remain unchanged.

Now all that you have to do is to experiment with building new configurations!