r'''
    Set the value of the setting for an IIS container.

    Args:
        name (str): The PSPath of the IIS webconfiguration settings.
        settings (list): A list of dictionaries containing setting name, filter and value.
        location (str): The location of the settings (optional)

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.set_webconfiguration_settings name='IIS:\' settings="[{'name': 'enabled', 'filter': 'system.webServer/security/authentication/anonymousAuthentication', 'value': False}]"

def set_webconfiguration_settings(name, settings, location=''):
    r'''
    Set the value of the setting for an IIS container.

    Args:
        name (str): The PSPath of the IIS webconfiguration settings.
        settings (list): A list of dictionaries containing setting name, filter and value.
        location (str): The location of the settings (optional)

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.set_webconfiguration_settings name='IIS:\' settings="[{'name': 'enabled', 'filter': 'system.webServer/security/authentication/anonymousAuthentication', 'value': False}]"
    '''

    ps_cmd = []

    if not settings:
        log.warning('No settings provided')
        return False

    settings = _prepare_settings(name, settings)

    # Treat all values as strings for the purpose of comparing them to existing values.
    for idx, setting in enumerate(settings):
        if setting['name'].split('.')[-1] != 'Collection':
            settings[idx]['value'] = six.text_type(setting['value'])

    current_settings = get_webconfiguration_settings(
        name=name, settings=settings, location=location)

    if settings == current_settings:
        log.debug('Settings already contain the provided values.')
        return True

    for setting in settings:
        # If the value is numeric, don't treat it as a string in PowerShell.
        if setting['name'].split('.')[-1] != 'Collection':
            try:
                complex(setting['value'])
                value = setting['value']
            except ValueError:
                value = "'{0}'".format(setting['value'])
        else:
            configelement_list = []
            for value_item in setting['value']:
                configelement_construct = []
                for key, value in value_item.items():
                    configelement_construct.append("{0}='{1}'".format(key, value))
                configelement_list.append('@{' + ';'.join(configelement_construct) + '}')
            value = ','.join(configelement_list)

        ps_cmd.extend(['Set-WebConfigurationProperty',
                       '-PSPath', "'{0}'".format(name),
                       '-Filter', "'{0}'".format(setting['filter']),
                       '-Name', "'{0}'".format(setting['name']),
                       '-Location', "'{0}'".format(location),
                       '-Value', '{0};'.format(value)])

    cmd_ret = _srvmgr(ps_cmd)

    if cmd_ret['retcode'] != 0:
        msg = 'Unable to set settings for {0}'.format(name)
        raise CommandExecutionError(msg)

    # Get the fields post-change so that we can verify tht all values
    # were modified successfully. Track the ones that weren't.
    new_settings = get_webconfiguration_settings(
        name=name, settings=settings, location=location)

    failed_settings = []

    for idx, setting in enumerate(settings):

        is_collection = setting['name'].split('.')[-1] == 'Collection'

        if ((not is_collection and six.text_type(setting['value']) != six.text_type(new_settings[idx]['value']))
                or (is_collection and list(map(dict, setting['value'])) != list(map(dict, new_settings[idx]['value'])))):
            failed_settings.append(setting)

    if failed_settings:
        log.error('Failed to change settings: %s', failed_settings)
        return False

    log.debug('Settings configured successfully: %s', settings)
    return True