Get started Bring yourself up to speed with our introductory content.

Add to your management toolbox with new DSC resources

Desired State Configuration is a powerful tool, but doesn't yet include many built-in resources. Learn how to find more and expand your repertoire.

If you're exploring the vast benefits of declarative configuration and drift management using Desired State Configuration, you're probably interested in applying it to your environment and have run out of the built-in resources included with the Windows Management Framework 4. Don't fear the lack of resources: Microsoft is rapidly releasing new ones, and I'll show you how to start using them in your configuration scripts.

If you haven't worked with Desired State Configuration (DSC) yet, you need to get started.

Once you have a DSC HTTP(S) Pull Server, it's up to you to start building configurations using the available DSC resources. When Windows Management Framework 4 (WMF 4) shipped, there weren't many resources available. In fact, there were just enough for you to start playing with DSC, but all that is changing. Microsoft is investing heavily in DSC and making new resources available every few months.

Microsoft and the PowerShell team are putting a lot of energy into DSC. At this moment, there are more than 50 DSC resources available -- if you know how to find them.

Let's start by looking at one of your existing servers running WMF 4. The Get-DSCResource cmdlet will list all the resources currently on your system. The original built-in resources are physically located in \%SystemDrive%\Windows\System32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\DSCResources and are really just modules that provide you with the configuration capability you need.

Keep in mind, if you use a resource in a configuration file, that resource must be available on each server using the new configuration. The benefit to the HTTP(S) Pull Server is that it will automatically download those resources to servers if needed. I like to make sure I have all my resources on the Pull Server. To check the Pull Server -- or any server, for that matter -- to see which DSC resources are currently installed use the Get-DSCResource cmdlet

Use the Get-DSCResource cmdlet to see which DSC resources are currently installed

The above list is just the original set of resources that shipped with WMF 4, but it's a good place to start. One challenge when writing a configuration is determining which options are required when a resource is used and how to script for them.

Exploring DSC resources

There is not a lot of documentation about how to use and script DSC resources in your configuration files. Although many examples are popping up on the website, you can determine how to use a resource all by yourself. PowerShell can help show you the parts you need.

Using the Get-DSCResource cmdlet, grab the specific resource you want and select Properties to see which properties are required and which values can be used with each property.

PS> Get-DscRersource -Name WindowsFeature | Select-Object -ExpandProperty Properties

Select Properties to see which properties are required

In this example, I'm examining the WindowsFeature resource that allows you to install or remove a Windows feature. Notice the ISMandatory and Value columns. In this case, the name of the Windows feature is the only mandatory attribute. The Ensure property allows you to specify Absent or Present, which means to remove or install the feature.

If I wanted to use this resource, I would need to specify the Windows feature name, such as web-server, and decide if I wanted it Present (installed). It would be even more helpful if PowerShell could show me a sample syntax using this resource, so I could quickly and correctly place it into my configuration script. The Get-DSCResource cmdlet has a special parameter that will achieve that result:

PS> Get-DSCResource -Name WindowsFeature -Syntax

DSC can show you a sample syntax using this resource

Just copy that script to the Node section of your configuration script. Remove the properties you don't want, and fill in the attributes of those you do. This takes all the guessing out of using the resource.

You can achieve the same results if you're using a scripting editor, like the PowerShell ISE, which can make the copy-and-paste process simpler.

You can also edit properties using a scripting editor, like the PowerShell ISE

My friend and PowerShell MVP Jeff Hicks shared an article recently where he created a new cmdlet New-DSCConfigurationTemplate that will get all the resources and the syntax, and put them into a nice script for you to examine and use.

He also came up with a cool way of making them snippets in your favorite scripting editor so you can call them up whenever they're needed.

Discovering additional DSC resources

As I mentioned earlier, Microsoft is working hard to provide more resources. The PowerShell community is also trying to help Microsoft by creating custom resources, but where do you find them?

First, some words of caution. The resources I'm about to help you find are experimental. In other words, they're not done yet and not supported. Microsoft is making them available so you can use them and provide feedback. Microsoft is updating these rapidly, so check back often. The links I'm providing are good today, but you should check the PowerShell Team blog for the latest information.

Currently, Microsoft is shipping the DSC Resource Kit Wave 3, which can be found at the TechNet Script Center.

Follow the simple installation instructions and you will have a new list of resources to work with. Everything I demonstrated earlier in this article works the same with the new resources.

Another way to get the new resources is by using the PowerShellGet cmdlet. This is a new technology that deserves its own article, but in a nutshell, it is a Microsoft-monitored NuGet repository that holds -- among other things -- the latest DSC resources. It's easy to use, and there are cmdlets that will download and install the resources, but it requires that you use the preview release of WMF 5. I want to reiterate: You can download the preview release of WMF 5, but don't use it in production yet.

If you want to try out WMF 5, you can get a list of cmdlets for PowerShellGet by using the following command:

PS> Get-Command -Module PowerShellGet

You can get a list of PowerShellGet cmdlets

The repository contains several modules you can install and try, but if you're just interested in the DSC resources, they begin with the letter X.

PS> Find-Module -Name X*

DSC resources begin with the letter X

To install all the new resources use:

PS> Install-Module -Name X*

Once installed, you can start exploring and using the new resources just as I described earlier by typing:

PS> Get-DSCResource -Name xVMHyperV –Syntax

Start using the new DSC resources

Keep checking for new releases of resources and don't forget to check the PowerShell community resources on the PowerShell website. Microsoft is moving fast with DSC, and many of us in the community are using and building new resources.

Dig Deeper on Microsoft Hyper-V management

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.