On this page

Applying and Monitoring PowerShell DSC Configurations

Updated on June 24, 2026

Enrico Hochkoeppler Profile

By Enrico Hochkoeppler

Web Developer & TutoriaLibre Founder

Desired State Configuration (DSC) is designed not only to define the desired state of a system but also to ensure that state is consistently applied, enforced, and monitored over time. The real power of DSC lies in its ability to detect and correct configuration drift automatically, ensuring that systems remain compliant with organizational standards even as changes occur. This is achieved through the Local Configuration Manager (LCM)—the engine that runs on every DSC-managed node—which applies configurations, checks for drift, and enforces compliance. Configurations can be applied in two modes: Push mode, where an administrator actively applies a configuration to a target node, and Pull mode, where nodes automatically retrieve their desired state from a remote pull service. Understanding how to apply, monitor, and troubleshoot DSC configurations is essential for maintaining consistent, secure, and performant systems at scale.


Applying a DSC Configuration​

Once a configuration has been written and compiled into a MOF file (Managed Object Format), it must be applied to the target node. The application process is handled by the Local Configuration Manager (LCM), which reads the MOF file and ensures the system matches the declared state.

Compiling the Configuration​

A configuration script produces MOF files when executed. For example, running the configuration name as a command generates a folder containing one MOF file per node:


WebServerConfig

This generates a folder containing one MOF file per node, such as:


.\WebServerConfig\Server01.mof

Code explanation: The MOF file is the actual document that DSC uses to enforce configuration. Each node has its own MOF file, allowing the same configuration to be applied to multiple machines with node-specific settings.

Applying the Configuration in Push Mode​

Push mode refers to a user actively applying a configuration to a target node by calling the Start-DscConfiguration cmdlet. To apply the configuration:


Start-DscConfiguration -Path .\WebServerConfig -Wait -Verbose

Code explanation:

By default, DSC runs a configuration as a background job. To run the configuration interactively, call Start-DscConfiguration with the -Wait parameter.

Applying the Configuration in Pull Mode​

In pull mode, pull clients are automatically configured to get their desired state configurations from a remote pull service. Each pull client has a scheduled event that performs a periodic compliance check of the node's configuration. When the event is triggered, the LCM on the pull client sends a request to the pull service to obtain the configuration specified in the LCM. The pull service acts as central control and manager for the configurations, ensuring that nodes conform to the desired state and reporting on their compliance status.

The pull server can be set up as an SMB-based pull server or an HTTPS-based server. The HTTPS-based pull server uses the Open Data Protocol (OData) with the OData Web service to communicate using REST APIs. This is the preferred model, as it can be centrally managed and controlled.


How the Local Configuration Manager (LCM) Enforces State​

The LCM is the engine that runs on every DSC-managed node. It is responsible for parsing and enacting configurations that are sent to the node. The LCM regularly polls the system using the control flow implemented by resources to maintain the state defined by a configuration. If the system is out of state, the LCM calls the code in resources to apply the configuration.

LCM Modes​

The LCM supports several configuration modes that determine how it handles drift:

ModeBehaviorApplyOnlyApplies the configuration once; no monitoring or correctionApplyAndMonitorApplies the configuration and reports drift but does not correct itApplyAndAutoCorrectApplies the configuration and automatically corrects drift

For large environments, ApplyAndAutoCorrect is the most common, as it ensures continuous compliance. When this mode is set, the LCM detects deviations from the desired state and automatically reapplies the configuration to bring the system back into compliance.

Viewing LCM Settings​

To view the current LCM settings on a node, use the Get-DscLocalConfigurationManager cmdlet:


Get-DscLocalConfigurationManager

This reveals important settings such as:

Code explanation: The output provides a comprehensive view of the LCM's behavior. For example, ConfigurationMode : ApplyAndMonitor indicates that the LCM monitors for drift but does not automatically correct it.

Configuring LCM Settings​

LCM settings are configured using a special type of configuration that applies to the LCM itself, rather than to the system. This is called a metaconfiguration. To specify an LCM configuration, use the DscLocalConfigurationManager attribute.

Example of an LCM configuration that sets the mode to ApplyAndAutoCorrect:


[DscLocalConfigurationManager()]

Configuration MyLCMConfig {

    Param([string]$ComputerName)

    Node ($ComputerName) {

        LocalConfigurationManager {

            ConfigurationMode = "ApplyAndAutoCorrect"

            ConfigurationModeFrequencyMins = 30

            RebootNodeIfNeeded = 'True'

            RefreshFrequencyMins = 15

        }

    }

}

Code explanation: This configuration defines the LCM settings for the specified node. ConfigurationMode = "ApplyAndAutoCorrect" enables automatic drift correction. ConfigurationModeFrequencyMins = 30 sets the drift check interval to 30 minutes. RebootNodeIfNeeded = 'True' allows the LCM to reboot the node if required. RefreshFrequencyMins = 15 sets how often the LCM checks for updated configurations.

After defining the LCM configuration, compile it to generate a .meta.mof file:


MyLCMConfig -OutputPath "C:\myDSC" -ComputerName localhost

Then apply the LCM settings using Set-DscLocalConfigurationManager:


Set-DscLocalConfigurationManager -Path "C:\myDSC"

Code explanation: The -Path parameter specifies the folder containing the .meta.mof file. The LCM reads this file and updates its settings accordingly.


Monitoring Configuration Status​

DSC provides built-in cmdlets to check the status of applied configurations and detect drift.

Checking the Current Configuration​

To display the configuration currently enforced on the node, use Get-DscConfiguration:


Get-DscConfiguration

This shows the actual state of all resources as defined by the applied configuration.

Checking the Last Configuration Run​

To retrieve detailed information about completed configuration runs, use Get-DscConfigurationStatus. By default, it returns information about the last configuration run:


$Status = Get-DscConfigurationStatus

$Status

The command returns a rich object that includes high-level information about whether the configuration run was successful or not. You can dig into the object to identify information about the configuration run, such as:

To retrieve information about all configuration runs (including consistency checks), use the -All parameter:


Get-DscConfigurationStatus -All

Code explanation: The -All parameter retrieves information about every configuration run on the system, not just the most recent one. This is useful for auditing historical compliance and identifying patterns of drift.

To check the status of a remote computer, use the -CimSession parameter:


$session = New-CimSession -ComputerName "Server01"

Get-DscConfigurationStatus -CimSession $session

Using Get-DscConfigurationStatus for Troubleshooting​

Get-DscConfigurationStatus is particularly useful for troubleshooting failed configurations. For example, you can examine the ResourcesNotInDesiredState property to identify which resources failed and why:


$Status = Get-DscConfigurationStatus

$Status.ResourcesNotInDesiredState

Code explanation: The ResourcesNotInDesiredState property lists all resources that are not in the desired state. Each entry includes the resource name, error details, and the specific configuration that failed. This information is essential for diagnosing and resolving configuration issues.


Detecting and Correcting Configuration Drift​

Configuration drift occurs when a system deviates from its declared state. Examples include:

The LCM periodically checks for drift based on its refresh interval. The frequency of these checks is controlled by the ConfigurationModeFrequencyMins setting.

Manual Drift Correction​

You can force DSC to reapply the current configuration using the -UseExisting parameter:


Start-DscConfiguration -UseExisting -Wait -Verbose

Code explanation: The -UseExisting parameter instructs the LCM to re-enforce the current MOF file without requiring a new MOF to be provided. This is useful when you suspect drift has occurred and want to manually restore compliance.

Automatic Drift Correction​

If the LCM is set to ApplyAndAutoCorrect, it will:

  1. Detect drift during its regular compliance check
  2. Automatically reapply the configuration
  3. Restore compliance without administrator intervention

This is one of DSC's most powerful features, enabling "set and forget" configuration management.

Testing Configuration Compliance​

To test whether the actual configuration on a node matches the desired configuration without applying changes, use Test-DscConfiguration:


Test-DscConfiguration

Code explanation: This cmdlet returns $true if the node is compliant and $false if drift has been detected. It does not make any changes to the system, making it safe to use in monitoring scripts.


Logging and Reporting​

DSC writes detailed logs that administrators can use for auditing and troubleshooting.

Viewing DSC Logs​

DSC logs are stored in the Windows Event Log under:


Applications and Services Logs → Microsoft → Windows → Desired State Configuration

These logs include:

Event logs are essential for diagnosing configuration failures. For example, if a script fails to run, you can examine the DSC operational log to identify the specific error.

Integration with Monitoring Systems​

DSC can integrate with enterprise monitoring and reporting systems:

Azure Monitor Logs provides greater operational visibility to your Automation State Configuration data and can help address incidents more quickly.


Summary​

Applying and monitoring configurations is the operational heart of DSC. The process involves:

DSC configurations are idempotent: the LCM ensures that machines are configured in whatever state the configuration declares, regardless of how many times the configuration is applied. This model ensures that systems remain consistent, predictable, and aligned with organizational standards, even in large and dynamic environments.

Found this helpful? Share the knowledge...

... or support this project to keep it alive!

Buy Me a Coffee

Previous

Resources and Configurations

Next

Performance Optimization