Start to Look at DSC

by May 22, 2014

Desired State Configuration (DSC) is a new feature in PowerShell 4.0. With DSC, you can write simple configuration scripts and apply them to the local or a remote machine. Here is a sample script to get you started:

Configuration MyConfig
  # Parameters are optional
  param ($MachineName)
  # A Configuration block can have one or more Node blocks
  Node $MachineName
    Registry RegistryExample
      Ensure = 'Present' # You can also set Ensure to "Absent"
      ValueName ='TestValue'
      ValueData ='TestData'

MyConfig -MachineName $env:computername -OutputPath c:\dsc
Start-DscConfiguration -Path c:\dsc -Wait 

The configuration "MyConfig" uses the resource "Registry" to make sure that a given Registry key is present. There are many more resources you can use in your DSC script, like adding (or removing) a local user or files, unpacking an MSI package or ZIP file, or starting or stopping a service, to name just a few.

Running the configuration will only create a MOF file. To apply the MOF file, use the Start-DSCConfiguration cmdlet. Use -Wait to wait for the configuration to take place. Else, the configuration will be done in the background using a job.

Twitter This Tip! ReTweet this Tip!