Search code examples
powershellpowershell-4.0

Refresh PowerShell DSC resource


I am debugging PowerShell DSC resources that come with v4.0. More specifically, I am testing MSFT_ProcessResource by adding a diagnostic log. After I make change to the resource, and run my configuration that exercise the resource, I don't see the logging I just added. Eventually after several minutes, PowerShell seems to refresh whatever cache of resource it has. I've tried Get-DscResource, and Import-Module MSFT_ProcessResource

None of which worked.

Is there a way to force re-loading the resource?


Solution

  • DSC engine caches resources to increase performance.

    There are two ways to reload the resource:

    1) Restart process hosting DSC engine (kill WMI Provider Host and re-run the configuration)

    2) Use debug mode which will cause DSC to reload resources automatically (useful when developing resources, but not recommended for regular work):

    LocalConfigurationManager
    {
        DebugMode = $true
    }
    

    You can read more about debug mode here: http://blogs.msdn.com/b/powershell/archive/2014/04/22/debug-mode-in-desired-state-configuration.aspx