Desired State Configuration (DSC)

Desired State Configuration (DSC) is a management platform in PowerShell that enables you to manage your IT and development infrastructure. It’s a declarative, model-driven solution that allows you to configure, deploy, and manage your infrastructure consistently across your organization.

What is DSC?

DSC allows you to define the desired state of your systems (like servers, applications, and environments) using configuration documents. These documents are written in a declarative syntax, meaning you specify *what* you want your system to look like, not *how* to achieve it. DSC then ensures that your systems are configured to match these desired states.

Key Concepts

Resources

DSC resources are the fundamental units of configuration. Each resource type has a defined set of properties that describe a specific aspect of a system. Examples of built-in DSC resources include:

You can also create custom DSC resources to manage any aspect of your infrastructure that isn't covered by the built-in resources.

Example: Managing a File

This example ensures a specific file exists with specific content.

Configuration SetFileContent
{
    Node 'localhost'
    {
        File HelloWorldFile
        {
            DestinationPath = "C:\Temp\HelloWorld.txt"
            Contents        = "Hello, DSC World!"
            Ensure          = "Present"
        }
    }
}

Configurations

A DSC configuration is a PowerShell script that contains one or more node blocks. Each node block defines the desired state for a specific target node.

Configurations are compiled into MOF (Managed Object Format) files, which are then applied to the target nodes.

Example: Simple Configuration

Configuration MyWebAppConfig
{
    Param (
        [string[]]$ComputerName = 'localhost'
    )

    Node $ComputerName
    {
        WindowsFeature IIS
        {
            Ensure = 'Present'
            Name   = 'Web-Server'
        }

        Service 'W3SVC'
        {
            Name = 'W3SVC'
            State = 'Running'
            DependsOn = '[WindowsFeature]IIS' # Ensure IIS is installed first
        }
    }
}

Local Configuration Manager (LCM)

The Local Configuration Manager (LCM) is the core engine on each target node responsible for executing DSC configurations. It handles:

You can configure the LCM's behavior, such as its refresh mode (pull or push) and how often it checks for configuration changes.

Getting Started

To start using DSC:

  1. Ensure you have PowerShell 5.0 or later installed.
  2. Define your desired state using DSC configuration scripts.
  3. Compile your configuration into a MOF file.
  4. Apply the MOF file to your target nodes using either a push mode (deploying directly from your management machine) or a pull server (where nodes check in to retrieve their configurations).

Advanced Topics

Explore the links in the sidebar for more detailed documentation on each of these topics.