What is DSC (Desired State Configuration)? A definitive guide, uses, and examples.

Last update: 09/05/2025
Author Isaac
  • DSC allows you to automate and maintain configurations on servers Windows, Linux and the cloud.
  • It works through declarative scripts, reusable resources, and the Local Configuration Manager (LCM) engine.
  • Facilitates mass management, automatic recovery, and compliance with security regulations.

Using DSC in PowerShell

IT infrastructure management has evolved by leaps and bounds in recent years, and one of the One of the tools that has revolutionized the management and configuration of systems the most is Desired State Configuration (DSC) from PowerShell. More and more professionals and companies are looking to automate server management, both on-premises and in the cloud, and the key question that arises is: What exactly is DSC and how can it fit into your daily life?

DSC is a solution that allows not only to declare how a system should be configured, but also ensuring that it remains that way at all times, automating the correction of deviations and facilitating scalability. In this article, we delve into how it works, its advantages, integration with different platforms, and real-life use cases, gathering all the reference information from various expert sources to give you a clear and comprehensive overview.

What is DSC (Desired State Configuration) and why has it revolutionized systems administration?

Desired State Configuration, better known by its acronym DSC, is a technology included in PowerShell since version 4.0, aimed at the automation and declarative management of configurations. OS, applications and services. This means that instead of writing extensive scripts with manual steps, you simply define the desired state, and DSC takes care of applying and maintaining those settings.

  • Standards-based automation: DSC is built on industry-standard models such as Open Management Infrastructure (OMI) and the Managed Object Format (MOF), allowing for integration into heterogeneous environments and cloud platforms.
  • Domain independence: Servers don't need to be domain-joined. DSC can manage individual machines or groups of servers, both physical and virtual, on-premises or in the cloud.
  • Infrastructure as Code (IaC): DSC allows you to treat server configuration as if it were code, storing scripts in version control systems and facilitating collaboration and automated deployment.

DSC in cloud and on-premises environments

Key principles and architecture of DSC

DSC is based on a simple yet powerful architecture consisting of three essential components: configurations, resources, and the Local Configuration Manager (LCM). These elements work together to ensure that the state of the systems is as you define it.

  • Configurations: These are scripts written in PowerShell that describe the desired state of the system. When executed, DSC creates MOF (Managed Object Format) files, which represent the desired state.
  • Resources: These are reusable blocks of code that implement specific tasks, such as managing files and services, configuring the registry, updating applications, or even deploying services like IIS or Active Directory. There are built-in and custom resources that you can develop according to your needs.
  • Local Configuration Manager (LCM): It is the DSC engine that resides in each managed system, responsible for applying or checking configurations at defined intervals. The LCM can operate in "push" mode (configuration sent from the administrator) or "pull" mode (the system consults a repository and applies the configuration when changes occur).

Additionally, DSC allows you to define the frequency of checks and, thanks to its event-based model and remote configuration, can detect unauthorized changes and automatically apply corrections. This reduces manual intervention, minimizes errors, and maintains consistency in large environments.

  How to uninstall apps on macOS: a complete, no-waste guide

Compatibility and usage scenarios: Windows, Linux, and the cloud

DSC supports most recent versions of Windows and, for several releases, has also supported Linux and cloud-hosted systems. Supported versions include:

  • Windows Server 2022, 2019 and 2016
  • Windows 11 and Windows 10
  • Azure Virtual Machines and other cloud platforms using specific extensions
  • Linux (with some specific features and through integration with OMI and CIM)

This versatility makes it easy for you to centrally manage physical servers, Virtual machines on-premises, as well as resources deployed in Azure, ensuring a consistent and replicable state regardless of location or operating system.

Automation with DSC and PowerShell in the cloud

Declarative programming: a paradigm shift in systems management

One of the great strengths of DSC is its declarative approach, as opposed to the programming traditional imperative. Instead of listing the steps one by one, only the expected final result is defined. The DSC engine itself deduces and executes the actions necessary to achieve that state.

Example: If you need a server to have IIS enabled and a certain environment variable, you'll define it in a configuration block. Then, whenever the system deviates from that state (for example, if someone accidentally uninstalls IIS), DSC will detect it and automatically restore the configuration.

The use of configuration blocks in PowerShell it is based on the keyword Configuration, specifying the necessary instructions and resources inside. When this configuration is executed, the MOF file is generated with the instructions, which the LCM will later use to apply them to the target system.

Getting Started with DSC: Basic Installation and Configuration

The starting point for working with DSC is to have the Windows Management Framework, which includes PowerShell and DSC. Installation is simple on modern systems, where it's usually already included. For older environments, it can be downloaded for free from the Microsoft website.

  • On Windows Server 2016 or higher, DSC is included by default.
  • For Windows Server 2012 R2 or 2008 R2, it is installed alongside the Windows Management Framework (starting with version 4.0).
  • On Linux systems, compatible agents and resources are used, usually integrated through OMI and distribution-specific packages.

Enabling remote administration via WinRM This is also a common requirement, which can be quickly done by running PowerShell as administrator:

Set-WSManQuickConfig -Force

This enables the remote management capabilities necessary for DSC to function even in massive deployment scenarios.

How do you write and apply a DSC configuration?

The typical process of using DSC follows a series of steps:

  1. Install the required DSC resource modules: You can download additional modules from the PowerShell Gallery using the cmdlet Install module, For example: Install-Module 'PSDscResources' -Verbose.
  2. Write the script Of configuration: A configuration block is created using PowerShell syntax, specifying the resources and parameters required by the system. For example, to define an environment variable:
Configuration CrearVariableEntorno {
  param ()
  Import-DscResource -ModuleName 'PSDscResources'

  Node localhost {
    Environment VariableExample {
      Name = 'TEST_ENV_VAR'
      Value = 'TestValue'
      Ensure = 'Present'
      Path = $true
      Target = @('Process', 'Machine')
    }
  }
}
CrearVariableEntorno -OutputPath:"./CrearVariableEntorno"
  1. Compile the configuration: Running the above script creates a folder with the configuration name (e.g., CreateEnvironmentVariable) and the MOF files generated for each defined node.
  2. Apply settings: The cmdlet is used Start-DscConfiguration specifying the path to the MOF file, for example: Start-DscConfiguration -Path './CrearVariableEntorno' -Wait -Verbose.
  3. Check status: With Get-DscConfiguration You can check the current status of the configuration on the node, and with Test-DscConfiguration verify whether the desired state is actually maintained.
  Wise Memory Optimizer Tutorial: Complete Step-by-Step Guide

The syntax of DSC scripts is simple and modular, allowing for the creation of reusable and easily versionable configurations in code control systems such as Git.

How to use .reg files to modify Windows settings-2
Related article:
How to use .reg files to modify Windows settings

Practical use cases: beyond the theory

DSC is especially useful in these scenarios:

  • Mass provisioning of servers: You can quickly and consistently deploy dozens or hundreds of machines (physical or virtual) with the exact configuration you need, for example, in lab deployments, development environments, or production environments.
  • Automatic recovery from incidents: If any critical service goes down or a configuration is altered by mistake, the Local Configuration Manager detects the deviation and restores the correct state, minimizing There of inactivity.
  • Maintaining security and compliance: DSC can be used to ensure that servers comply with standard regulations and guidelines (e.g., NIST SP 800-53, FISMA), applying configurations that strengthen security, and monitoring for any improper changes.
  • Multi-platform resource management: Thanks to its compatibility with Linux and the cloud (especially Azure), DSC is a key tool for hybrid environments, integrating with other configuration managers such as Puppet or Chef.

Advanced example: Imagine you are deploying a farm SharePoint in Azure. Using DSC, you can define all the necessary roles, features, services, and users; then, through integrations with Azure Automation or custom scripts, apply those configurations to each machine, ensuring they all meet the same requirements and remain that way across reboots, upgrades, or changes.

Using DSC in Azure: Cloud Extension and Automation

In cloud environments, DSC takes on even greater relevance, as it enables automated configuration management of large-scale virtual machines. Azure has a DSC-specific extension which makes it easy to deliver and apply configurations directly from portals, ARM templates, the Azure CLI, or PowerShell scripts.

  • Integration with Azure VM Extensions: Allows you to apply configurations to new or existing VMs, in an automated manner during deployment.
  • Azure Automation State Configuration: Provides centralized management and monitoring of all DSC configurations across Azure resources, with reporting on status and compliance.
  • Support for auto-update policies: You can activate options such as AutoUpdate so that extension versions are always kept up to date, minimizing security risks.

Using DSC in Azure integrates seamlessly with Azure Resource Manager (ARM) templates, allowing you to define the entire infrastructure and its configurations as code, deploying complex environments with just a few lines of configuration.

Good practices and recommendations for effective use of DSC

To get the most out of DSC, it's important to follow a few tips:

  • Modularize your configurations: Divide your infrastructure into small, reusable configurations. This makes maintenance and upgrades much easier.
  • Use version control: Storing configuration scripts in Git repositories will allow you to track changes, facilitate collaboration, and recover previous versions when necessary.
  • Test before deploying: Always validate your configurations in test environments to ensure they work as expected and don't introduce unexpected conflicts. Tools like Pester can help you automate these tests.
  • Download official and updated resources: Use the PowerShell Gallery to get the latest resources and modules, avoiding incompatibilities or security issues.
  • Document all settings: Add clear comments to your scripts, indicating what each thing is for, dependencies, and any details important to the team.
  Tips on how to Allow or Disable Autofill in Chrome Browser

Advanced aspects: partial configuration management, pull mode and security

DSC also supports advanced features that allow you to handle complex scenarios:

  • Partial configurations: You can divide a large configuration into several independent fragments, facilitating management and incremental deployment. LCM combines the fragments into a single final configuration.
  • Push and Pull Modes: In Push mode, the administrator manually pushes the configuration to the nodes; in Pull mode, the nodes query a central server or repository to automatically download and apply updated configurations.
  • LCM Customization: The Local Configuration Manager allows you to adjust parameters such as the polling interval (RefreshFrequencyMins), the check mode (ConfigurationMode) or the frequency of application (ConfigurationModeFreqencyMins). This provides complete flexibility and allows adaptation to any type of environment.
  • Enhanced security: All DSC processes can be audited using Windows event logs (for example, in Microsoft-Windows-Dsc/Operational), helping to detect and resolve any incidents, and enabling compliance with international safety standards.
how to use ssh from powershell-1
Related article:
Complete Guide to Using SSH from PowerShell: Configuration and Practical Examples

Common errors and how to solve them when working with DSC

As with any technology, problems can arise when using DSC due to incorrect configurations, module incompatibilities, or insufficient permissions. The most common errors are usually related to:

  • Permissions: Make sure you run PowerShell with administrator privileges and that the accounts used have sufficient access to the system and defined resources.
  • Syntax errors: Carefully review the syntax of the configuration scripts, especially the Node blocks and resource definitions.
  • Outdated modules: Always download the latest versions from the PowerShell Gallery and keep the Windows Management Framework up to date.
  • Settings that do not apply: Check the logs and use the cmdlets Get-DscConfiguration y Test-DscConfiguration to diagnose the status of the nodes.

Additionally, the PowerShell and Microsoft community offers extensive documentation, forums, and resources to address any questions or issues.

Related article:
How do I change the settings to download from Wi-Fi or mobile data on my iPhone?