Remove-DscConfigurationDocument -Stage Current, Pending, Previous -Verbose


Using PowerShell 5.0
I have a current configuration that configures my server. I would like to modify this configuration so that the last step removes the mof file from the system (c:\windows\system32\configuration).
How can I use the following cmdlet in my configuration?`

Remove-DscConfigurationDocument -Stage Current, Pending, Previous -Verbose

Should I make a custom dscressource that uses the cmdlet or do i add a script block at the end of the configuration that runs the cmdlet above at all runs?

any tips/hints are welcome:)


Bjørn Roalkvam

This was an awesome experiment. Summary:
Removing the configuration is really an orchestration level event that should/must take place outside of DSC.

What happens if you try to run Remove-DSCConfigurationDocument from inside a DSC configuration?
The configuration will fail with the following error.
Cannot invoke the Remove-DscConfigurationDocument cmdlet. The Start-DscConfiguration cmdlet is in progress and must return before Remove-DscConfigurationDocument can be invoked.

What happens if you use the File resource to remove all versions of the MOF from a configuration?
The Previous.MOF file was cleanly deleted. The Current.MOF file was not found because it didn’t exist yet, and was present on the system after the configuration completed. The Pending.MOF file was deleted but that caused the configuration to fail when it attempted to copy Pending to Current.

Hi Michael,

I got the same results as you. My solution was to make a PS script that runs the Remove-DscConfigurationDocument cmdlet + sets the LCM settings to not reboot.