Remove the current DSC Configuration. Removes current, pending, and previous
    dsc configurations.

    .. versionadded:: 2017.7.5

    Args:
        reset (bool):
            Attempts to reset the DSC configuration by removing the following
            from ``C:\\Windows\\System32\\Configuration``:

            - File: DSCStatusHistory.mof
            - File: DSCEngineCache.mof
            - Dir: ConfigurationStatus

            Default is False

            .. warning::
                ``remove_config`` may fail to reset the DSC environment if any
                of the files in the ``ConfigurationStatus`` directory. If you
                wait a few minutes and run again, it may complete successfully.

    Returns:
        bool: True if successful

    Raises:
        CommandExecutionError: On failure

    CLI Example:

    .. code-block:: bash

        salt '*' dsc.remove_config True

def remove_config(reset=False):
    '''
    Remove the current DSC Configuration. Removes current, pending, and previous
    dsc configurations.

    .. versionadded:: 2017.7.5

    Args:
        reset (bool):
            Attempts to reset the DSC configuration by removing the following
            from ``C:\\Windows\\System32\\Configuration``:

            - File: DSCStatusHistory.mof
            - File: DSCEngineCache.mof
            - Dir: ConfigurationStatus

            Default is False

            .. warning::
                ``remove_config`` may fail to reset the DSC environment if any
                of the files in the ``ConfigurationStatus`` directory. If you
                wait a few minutes and run again, it may complete successfully.

    Returns:
        bool: True if successful

    Raises:
        CommandExecutionError: On failure

    CLI Example:

    .. code-block:: bash

        salt '*' dsc.remove_config True
    '''
    # Stopping a running config (not likely to occur)
    cmd = 'Stop-DscConfiguration'
    log.info('DSC: Stopping Running Configuration')
    try:
        _pshell(cmd)
    except CommandExecutionError as exc:
        if exc.info['retcode'] != 0:
            raise CommandExecutionError('Failed to Stop DSC Configuration',
                                        info=exc.info)
        log.info('DSC: %s', exc.info['stdout'])

    # Remove configuration files
    cmd = 'Remove-DscConfigurationDocument -Stage Current, Pending, Previous ' \
          '-Force'
    log.info('DSC: Removing Configuration')
    try:
        _pshell(cmd)
    except CommandExecutionError as exc:
        if exc.info['retcode'] != 0:
            raise CommandExecutionError('Failed to remove DSC Configuration',
                                        info=exc.info)
        log.info('DSC: %s', exc.info['stdout'])

    if not reset:
        return True

    def _remove_fs_obj(path):
        if os.path.exists(path):
            log.info('DSC: Removing %s', path)
            if not __salt__['file.remove'](path):
                error = 'Failed to remove {0}'.format(path)
                log.error('DSC: %s', error)
                raise CommandExecutionError(error)

    dsc_config_dir = '{0}\\System32\\Configuration' \
                     ''.format(os.getenv('SystemRoot', 'C:\\Windows'))

    # Remove History
    _remove_fs_obj('{0}\\DSCStatusHistory.mof'.format(dsc_config_dir))

    # Remove Engine Cache
    _remove_fs_obj('{0}\\DSCEngineCache.mof'.format(dsc_config_dir))

    # Remove Status Directory
    _remove_fs_obj('{0}\\ConfigurationStatus'.format(dsc_config_dir))

    return True