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

This topic contains 2 replies, has 2 voices, and was last updated by  Bjørn Roalkvam 2 hours, 5 minutes ago.

  • Author
    Posts
  • #100773

    Bjørn Roalkvam
    Participant

    Hi

    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:)

    brgs

    Bjørn Roalkvam

  • #100789

    Michael Greene
    Participant

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

    Test:
    What happens if you try to run Remove-DSCConfigurationDocument from inside a DSC configuration?
    Result:
    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.

    Test:
    What happens if you use the File resource to remove all versions of the MOF from a configuration?
    Result:
    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.

  • #101037

    Bjørn Roalkvam
    Participant

    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.

You must be logged in to reply to this topic.