Recently I got question from one developer that uses DSC about DSC configuration documents (MOF files) that are used for current configuration and he did not believe me that MOF file for current configuration is just a file in C:\Windows\System32\Configuration directory.

I would like to present you a simple piece of code that shows you MOF files and process how to remove them. It is possible to remove them using cmdlet Remove-DscConfigurationDocument or you can simply delete them. Remove-DscConfigurationDocument cmdlet could be for example useful in Pester test file to clean all system changes that was done in order to test custom DSC resource.

You can see Current.mof and Previous.mof. I do not have any pending configuration but if I have it then you will see Pending.mof file.

Current.mof

Get-ChildItem -Path 'C:\Windows\System32\Configuration' -File -Force

    Directory: C:\Windows\System32\Configuration


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       2015-06-01     04:49           2182 Current.mof
-a----       2015-06-01     04:49            558 DSCEngineCache.mof
-a----       2015-06-01     04:51           1006 DSCResourceStateCache.mof
-a----       2015-06-01     04:49           3640 DSCStatusHistory.mof
-a----       2015-06-01     04:24           1332 MetaConfig.mof
-a----       2015-06-01     04:49           2180 Previous.mof

Remove all

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

VERBOSE: An LCM method call arrived from computer DSCTESTCOMP with user sid
S-.....................
VERBOSE: [DSCTESTCOMP]: LCM:  [ Start  Remove   ]
VERBOSE: [DSCTESTCOMP]:                            [] Configuration document Current was removed
VERBOSE: [DSCTESTCOMP]:                            [] The Local Configuration Manager did not find configuration
checksum file to remove.
VERBOSE: [DSCTESTCOMP]:                            [] The Local Configuration Manager did not find any pending
configuration to remove.
VERBOSE: [DSCTESTCOMP]:                            [] Configuration document Previous was removed
VERBOSE: [DSCTESTCOMP]: LCM:  [ End    Remove   ]
VERBOSE: [DSCTESTCOMP]: LCM:  [ End    Remove   ]    in  0.0000 seconds.

And check again

Get-ChildItem -Path 'C:\Windows\System32\Configuration' -File -Force

    Directory: C:\Windows\System32\Configuration


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       2015-06-01     04:52            558 DSCEngineCache.mof
-a----       2015-06-01     04:51           1006 DSCResourceStateCache.mof
-a----       2015-06-01     04:52           4004 DSCStatusHistory.mof
-a----       2015-06-01     04:24           1332 MetaConfig.mof
« Previous Next »