Skip to content

Declarative Configuration

Desired State Configuration (DSC) is built on a declarative model. In a declarative system, you do not write instructions that describe how to configure a machine. Instead, you describe what the final state must be, and the DSC engine determines how to achieve and maintain that state. This approach is fundamentally different from traditional scripting, which is procedural and step‑by‑step.

Declarative configuration is the core principle that makes DSC predictable, scalable, and resilient in large environments.


1. Declarative vs. Imperative Approaches

To understand declarative configuration, it is useful to contrast it with the imperative model.

Imperative (traditional scripting)

You write explicit steps:

  • Install this feature
  • Start this service
  • Create this file
  • Set this registry key

The script must define the entire procedure. If something changes later—such as a service stopping—you must run the script again or write additional logic to detect and correct the issue.

Declarative (DSC)

You describe the desired end state:

  • The feature must be installed
  • The service must be running
  • The file must exist
  • The registry key must have this value

DSC determines how to enforce that state and continuously ensures the system remains compliant.


2. How Declarative Configuration Works in DSC

A DSC configuration is a PowerShell script that uses a special syntax to declare the desired state of system components. The configuration does not contain procedural logic. Instead, it defines resources, each representing a part of the system.

Example of a declarative configuration

Configuration WebServerConfig {
    Node "Server01" {

        WindowsFeature WebServer {
            Name   = "Web-Server"
            Ensure = "Present"
        }

        Service W3SVC {
            Name        = "W3SVC"
            State       = "Running"
            StartupType = "Automatic"
        }
    }
}

Explanation

  • Configuration defines a DSC configuration block.
  • Node specifies the target machine.
  • WindowsFeature is a DSC resource that manages Windows features.
  • Ensure = "Present" declares that the feature must be installed.
  • Service is a resource that manages Windows services.
  • State = "Running" declares that the service must be running.

Notice that the configuration does not specify commands like Install-WindowsFeature or Start-Service.

It simply declares the desired state.


3. The Role of the Local Configuration Manager (LCM)

The LCM is the engine on each DSC‑managed node. It interprets the declarative configuration and ensures compliance.

The LCM:

  • Reads the configuration
  • Determines what is already correct
  • Applies changes only where needed
  • Periodically checks for drift
  • Automatically corrects deviations

Because the configuration is declarative, the LCM can safely reapply it at any time.


4. Idempotence: A Key Benefit of Declarative Configuration

Declarative resources in DSC are idempotent, meaning:

  • Applying the same configuration multiple times produces the same result
  • No duplicate actions occur
  • No harm is done by reapplying configurations

For example, if a feature is already installed, DSC does nothing.

If a service is already running, DSC does nothing.

If a file already exists with the correct content, DSC does nothing.

This makes DSC safe to run repeatedly across large environments.


5. Why Declarative Configuration Matters at Scale

Declarative configuration is essential for environments where:

  • Many machines must be configured identically
  • Configuration drift must be prevented
  • Compliance must be enforced
  • Systems must be rebuilt or replaced quickly
  • Automation must be predictable and repeatable

Declarative models eliminate the complexity of procedural scripts and allow administrators to focus on defining the correct state rather than writing logic to achieve it.


6. Summary

Declarative configuration is the foundation of DSC. It allows administrators to:

  • Describe the desired state of a system
  • Avoid writing procedural logic
  • Rely on the LCM to enforce and maintain compliance
  • Achieve idempotent, predictable automation
  • Scale configuration management across large environments

By shifting from “how to configure” to “what the configuration must be,” DSC provides a powerful, reliable, and maintainable approach to managing systems at scale.