Playing with PowerShell Desired State Configuration

One of the challenges I’ve set myself over the last nine months or so is that I try to do as much configuration work as possible with PowerShell instead of the GUI tools.  It’s a great way to save time, but also to force me to get more used to PowerShell.  One of the new features announced at TechEd North America is Desired State Configuration (DSC).  DSC allows you to specify a configuration, and then tell PowerShell to “make it so”.  I’m doing some playing around with the Windows Azure Pack in Windows Server 2012 R2 Preview, so what better time to also have a play with DSC?

From what I’ve seen so far, DSC is a declarative style of building configurations, focussing on the end state, rather than the process of getting to the end state.  This means you can define a simple configuration like:

Node localhost


Package WebPI

        Ensure = “Present”
Path = “$Env:SystemDrive\Source\WebPlatformInstaller_amd64_en-US.msi”
Name = “Web Platform Installer”
ProductId = “458707CD-9D7A-477F-B925-02242A29673B”


This is a simple configuration that defines that a server needs to have the Web Platform Installer application installed.

The Package keyword (or “Resource” to use it’s official name) tells DSC that we’re looking at an application that needs to be in place.  There are a number of resources in the box for DSC documented here.  The “Ensure = “present”” line defines that the software should be in place and the Path line defines where the software source is if it needs to be installed.  The ProductId is the detection mechanism – how does DSC figure out if it needs to do anything.  If this strikes you as very similar to System Center Configuration Manager’s application model, you’re not the only one!

So what does this have to do with Azure Pack?  Well, if you’ve had a look at it you’ll see there is a bunch of pre-configuration to do on the machines you use if you’re doing a distributed install, especially for the web hosting component.  I decided to use the opportunity to learn DSC as well as Azure Pack.  What I’ve built is an initial configuration file that will enable all the appropriate operating system components, and install the Web Platform Installer so I can use it to download the Azure Pack components.  I could simply do all the configuration with WebPI, but where’s the learning opportunity in that?

To set this up, you will need to create a directory in C:\ called source, and then download the Web Platform Installer from here and save it into that directory.  Now you can use DSC to configure your machine.  Start by executing the PowerShell configuration file here


If it’s worked correctly you will see a subdirectory created called AzurePackWebConfig with a MOF file in it.  Then, you can apply the configuration

start-dscconfiguration –verbose –wait –path .\AzurePackWebConfig

And then wait as the configuration is applied.  And it’s as easy as that.

My next challenge is to modify the DSC configuration to include the firewall configuration by using the “Script” resource.  Stay tuned for a further blog post!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s