How to setup Debug Mode in Windows PowerShell Desired State Configuration (DSC)

If you work on custom DSC resources then debug mode is very handy for you because you may need to re-import your updated DSC resource again and again. Without re-import (force import) the DSC uses cache.

How to set DebugMode:

  • None
    • Signifies that DebugMode is False and not applicable.
  • ForceModuleImport
    • Enforce the resource module to be reloaded instead of using the cache. This is similar to “true” value in previous versions.
  • ResourceScriptBrealAll
    • Helps in debugging DSC resources when Local configuration manager tries to execute their functions. More on it in subsequent blog posts!
  • All
    • Signifies that debugging as well as reloading of modules are both enabled.
[DSCLocalConfigurationManager()]
Configuration LCMDebugMode {
    Node localhost {
        Settings {
            ConfigurationMode    = 'ApplyOnly'
            RefreshMode          = 'Push'
            Debugmode            = 'ForceModuleImport'
        }
    }
}

LCMDebugMode -OutputPath $directoryPath
Set-DscLocalConfigurationManager -Path $directoryPath -Verbose
Get-DscLocalConfigurationManager

The second option to mitigate cache is to restart service but this is not recommended procedure:

Restart-Service -Name winmgmt -Force -Verbose

Leave a Reply

Your email address will not be published. Required fields are marked *