Skip to content

LCM Settings

PowerShell Desired State Configuration (DSC) relies on the Local Configuration Manager (LCM) to enforce and maintain the desired state of a target node. Properly configuring LCM settings ensures consistent behavior, efficient resource management, and controlled reboot handling. This section covers critical LCM settings such as RefreshMode, ConfigurationMode, and reboot control options to optimize DSC operations.


LCM RefreshMode and ConfigurationMode

The LCM uses RefreshMode and ConfigurationMode to determine how it applies configurations and monitors compliance. These settings are defined in the LCM configuration file (.mof) or via Set-DscLocalConfigurationManager.

RefreshMode

Controls how the LCM applies configurations and checks compliance: - ApplyAndMonitor: Applies configurations and continuously monitors compliance (default).
- ApplyAndRebootIfNeeded: Applies configurations and reboots if required (e.g., for OS-level changes).
- ApplyOnly: Applies configurations once without ongoing monitoring.

Example:

Configuration LCMConfig {
    Node localhost {
        Settings {
            RefreshMode = 'ApplyAndRebootIfNeeded'
            ConfigurationMode = 'ApplyAndMonitor'
        }
    }
}
LCMConfig
Start-DscConfiguration -Wait -Force -Verbose

ConfigurationMode

Determines how the LCM enforces compliance: - ApplyAndMonitor: Applies configurations and checks compliance repeatedly (default).
- ApplyAndRebootIfNeeded: Applies configurations and reboots if needed.
- ApplyOnly: Applies configurations once without monitoring.
- AuditOnly: Only audits compliance without making changes.

Example:

Set-DscLocalConfigurationManager -NodeName localhost -ConfigurationMode 'AuditOnly'


Reboot Control

The LCM can be configured to handle reboots gracefully, avoiding unintended disruptions. Key settings include:

RebootNodeIfRequired

Controls whether the LCM reboots the node after applying configurations: - True: Reboots if required (default).
- False: Defers reboots to manual intervention.

Example:

Set-DscLocalConfigurationManager -NodeName localhost -RebootNodeIfRequired $false

AllowModuleOverwrite

Allows overwriting existing DSC modules during configuration. Use with caution, as it can introduce instability.

Example:

Set-DscLocalConfigurationManager -NodeName localhost -AllowModuleOverwrite $true


Managing LCM Configuration Files

The LCM configuration is defined in a .mof file, typically generated by a DSC configuration script. For example:

Configuration LCMConfig {
    Node localhost {
        Settings {
            RefreshMode = 'ApplyAndRebootIfNeeded'
            ConfigurationMode = 'ApplyAndMonitor'
            RebootNodeIfRequired = $true
        }
    }
}
LCMConfig
Start-DscConfiguration -Wait -Force -Verbose

This script sets the LCM to reboot if required and continuously monitor compliance.


Key takeaways

  • RefreshMode and ConfigurationMode dictate how DSC enforces and monitors compliance.
  • RebootNodeIfRequired controls whether the LCM triggers reboots after configuration.
  • Use AllowModuleOverwrite sparingly to avoid unintended module conflicts.
  • Always test LCM changes in a non-production environment before deploying.
  • LCM settings can be configured via .mof files or Set-DscLocalConfigurationManager.