My Profile Photo

Ashley Poole

- Speaker -
- Senior Software Developer -
- Co-organiser of @ShropshireDevs -
- Site Reliability Engineering Advocate -

Quick Desired State Configuration Example

Desired State Configuration (DSC) allows for the ability to configure the state of Windows devices running Powershell V4. This is very similar to solutions like Chef and Puppet which mainly focus on Linux based devices although DSC can be tied into these other solutions to configure Windows devices. The stages to DSC are:

  1. Author - Creating your configuration
  2. Stage - Converting your configuration to .MOF
  3. Apply - Running the .MOF file (Your configuration) .MOF stands for Management Object Format.

More on the .MOF can be found here.

Basic DSC Example


Configuration WebServer # Configuration name

    param ( $NodeName ) # Server name as parameter

    Node $NodeName # Configuration block for each server
        # Install IIS       
        WindowsFeature IIS
            Ensure = "Present" # 'Absent' or 'Present'
            Name = "Web-Server"}

        # Install MyWebsite Folder
        File MyWebsiteDirectory
            Ensure = "Present"
            Type = "Directory" # 'File' or 'Directory'
            SourcePath = $MyWebsiteFiles # Source files to populate destination
            DestinationPath = "E:websMyWebsite"
            DependsOn = "WindowsFeature]IIS # Depend on 'WindowsFeature IIS'



The below command will compile the DSC configuration called WebServer to .MOF files for each NodeName listed.

WebServer -NodeName "SVR01","SVR02"


To apply the configuration, your need to use the Start-DSCConfiguration cmdlet which is part of the PSDesiredStateConfiguration module. The cmdlet will copy the .MOF files to the specified servers and use the specified servers Local Configuration Manager (LCM) engine to comply with the configuration.

Start-DSCConfiguration -Path .WebServer -Wait -Verbose -Force

For a list of other built in DSC resources check here.

Posted on Blog, DevOps, DSC, Knowledge Base, Powershell, Server Administration

comments powered by Disqus