Configuration in a DevOps world - Windows PowerShell Desired State Configuration

Configuration in a DevOps world - Windows PowerShell Desired State Configuration

Rate This
  • Comments 7
Some background
A new breed of configuration management tools has been created to manage the platforms, applications, and infrastructure of the cloud, and keep the cloud running with high availability. The need for these new tools and infrastructure comes from the increase in scale, rapid rate of change, and complexity of the cloud. But existing tools have limited support for Windows.

Windows PowerShell Desired State Configuration (DSC) provides a configuration platform built into Windows that is based on open standards. DSC is flexible enough to function reliably and consistently in each stage of the deployment lifecycle (development, test, pre-production, production), as well as during scale-out, which is required in the cloud world.

What it is
DSC gives you a powerful and easy way to manage your Windows infrastructure, both on-premise and in the cloud. It does this by introducing a very simple declarative syntax into the PowerShell language, and a built-in engine that receives and applies the configuration. You describe the desired state of your environment by using this new declarative syntax, and then distribute it to each target node in your environment where it is made so. After the configuration is delivered and applied, it can be used to correct configuration drift when it occurs, or just report on configuration drift, so that you know that it has occurred.

How it is different
You might be thinking, “I can already use PowerShell to manage my infrastructure, why would I want to use DSC?” First of all, as mentioned above, the DSC syntax is declarative, which makes authoring and maintaining the configuration much easier. For example, the DSC configuration below makes sure that Web Server (IIS) and ASP are installed on Server1 and Server2:

Configuration
IISWebsite
{
       Node Server1, Server2
       {
           WindowsFeature IIS
           {
                  Ensure    = “Present”
                  Name      = “Web-Server”
           }

            WindowsFeature ASP
           {
                  Ensure    = “Present”
                  Name      = “Web-Asp-Net45”
           }
    }
}

As you can see with this new syntax, you can simply declare the state you want your target devices to be in, instead of writing instructions for how to put them in that state. This makes it much less costly for you to learn, adopt, implement, and maintain configuration through DSC.
Something else that you might have noticed in the above example is the lack of error handling. There is no need to complicate your DSC scripts with error handling, because errors are caught, reported and logged by the DSC infrastructure automatically. This makes your DSC scripts much more readable than typical PowerShell scripts.

A key concept of DSC that you cannot see in the above example is that it is inherently idempotent. Idempotent configurations ensure that the desired state will be reached by applying the entire configuration, regardless of the current state. This means that without adding convoluted logic to your script, you can make and deploy incremental changes to your configuration over time without fear of putting your systems into a bad state. PowerShell scripts can also be written in an idempotent way, but cannot be enforced; with PowerShell scripts, it’s also more difficult to get it right, especially when you’re trying to ensure that your scripts will remain readable and maintainable.

Like PowerShell scripts, DSC configurations can be pushed to target nodes, but this has complications in many environments, like allowing the incoming connections through firewall ports. To get around this, DSC has a built-in feature that allows configurations to be pulled from a central location over standard web protocols. The built-in “pull” functionality means that opening new firewall ports is not required. An additional benefit of pulling configurations is that required Windows PowerShell modules can also be pulled from the central location using same web protocols. This means that modules that are required by a configuration do not need to be on the target before you deploy a configuration, because they are pulled down on demand.

More to come

DSC is an exciting new addition to PowerShell, and we have only touched on very high-level concepts in this post; but I hope it has piqued your interest in learning more about DSC. We will be publishing many more posts over the coming days and weeks that will dig into the details of DSC, so stay tuned. In the meantime, I invite you to dig into DSC and see what it can do for you.

DSC is available as part of Windows 8.1 and Windows Server 2012 R2; you can start building configuration files in Windows PowerShell ISE if you’re running either of those new operating systems.  If you’re running Windows 7, Windows Server 2008 R2, or Windows Server 2012, install Windows Management Framework 4.0 to get the benefits of DSC.  Learn more about how to get started from the DSC documentation on Microsoft TechNet.

Enjoy!

Mark Gray
Senior Program Manager
Microsoft

Leave a Comment
  • Please add 4 and 5 and type the answer here:
  • Post
  • Was looking to play around with DSC in Office.

    Finally WMF 4.0 is available for WIndows 7 , Server 2008 R2.....

    Thanks to the PowerShell team for all the efforts :)

    Cheers

  • Is this similar to Desired Configuration Management (DCM) by SCCM?

  • Just for the record, this is CFengine's model and dates back to 1993.

  • ...and it's Puppet's syntax, which dates back to 2005, on Unix.

  • Why?? Why copy Puppet syntax and try to re-invent the wheel?

    Check out puppetlabs.com/.../part-top-questions-on-puppet-and-windows and puppetlabs.com/.../part-2-top-questions-on-puppet-and-windows

  • When trying a very simple configuration:

    Configuration XPSViewer

    {

       WindowsFeature xpsViewer

       {

           Name = 'XPS-Viewer'

           Ensure = 'Present'

       }

    }

    I get an error when I try to execute is to create the MOF:

    PSDesiredStateConfiguration\Configuration : The property 'CommandType' cannot be found on this object

    Am I missing something in my installation (Windows Server 2012R2)

  • I, too, kept getting the "The property 'CommandType' cannot be found on this object" error message when executing my configuration.  It turns out that at least some of the DSC syntax doesn't conform to StrictMode.  To resolve this, I had to call "Set-StrictMode -Off" to disable it (since I had already enabled it).  I've now added "Set-StrictMode -Off" inside my Configuration, after the Param statement, to ensure it is always off within the configuration context.

Page 1 of 1 (7 items)