r'''
    Get the webconfiguration settings for the IIS PSPath.

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

    Returns:
        dict: A list of dictionaries containing setting name, filter and value.

    CLI Example:

    .. code-block:: bash

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

def get_webconfiguration_settings(name, settings, location=''):
    r'''
    Get the webconfiguration settings for the IIS PSPath.

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

    Returns:
        dict: A list of dictionaries containing setting name, filter and value.

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.get_webconfiguration_settings name='IIS:\' settings="[{'name': 'enabled', 'filter': 'system.webServer/security/authentication/anonymousAuthentication'}]"
    '''
    ret = {}
    ps_cmd = []
    ps_cmd_validate = []

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

    settings = _prepare_settings(name, settings)
    ps_cmd.append(r'$Settings = New-Object System.Collections.ArrayList;')

    for setting in settings:

        # Build the commands to verify that the property names are valid.

        ps_cmd_validate.extend(['Get-WebConfigurationProperty',
                                '-PSPath', "'{0}'".format(name),
                                '-Filter', "'{0}'".format(setting['filter']),
                                '-Name', "'{0}'".format(setting['name']),
                                '-Location', "'{0}'".format(location),
                                '-ErrorAction', 'Stop',
                                '|', 'Out-Null;'])

        # Some ItemProperties are Strings and others are ConfigurationAttributes.
        # Since the former doesn't have a Value property, we need to account
        # for this.
        ps_cmd.append("$Property = Get-WebConfigurationProperty -PSPath '{0}'".format(name))
        ps_cmd.append("-Name '{0}' -Filter '{1}' -Location '{2}' -ErrorAction Stop;".format(setting['name'], setting['filter'], location))
        if setting['name'].split('.')[-1] == 'Collection':
            if 'value' in setting:
                ps_cmd.append("$Property = $Property | select -Property {0} ;"
                              .format(",".join(list(setting['value'][0].keys()))))
            ps_cmd.append("$Settings.add(@{{filter='{0}';name='{1}';location='{2}';value=[System.Collections.ArrayList] @($Property)}})| Out-Null;"
                          .format(setting['filter'], setting['name'], location))
        else:
            ps_cmd.append(r'if (([String]::IsNullOrEmpty($Property) -eq $False) -and')
            ps_cmd.append(r"($Property.GetType()).Name -eq 'ConfigurationAttribute') {")
            ps_cmd.append(r'$Property = $Property | Select-Object')
            ps_cmd.append(r'-ExpandProperty Value };')
            ps_cmd.append("$Settings.add(@{{filter='{0}';name='{1}';location='{2}';value=[String] $Property}})| Out-Null;"
                          .format(setting['filter'], setting['name'], location))
        ps_cmd.append(r'$Property = $Null;')

    # Validate the setting names that were passed in.
    cmd_ret = _srvmgr(cmd=ps_cmd_validate, return_json=True)

    if cmd_ret['retcode'] != 0:
        message = 'One or more invalid property names were specified for the provided container.'
        raise SaltInvocationError(message)

    ps_cmd.append('$Settings')
    cmd_ret = _srvmgr(cmd=ps_cmd, return_json=True)

    try:
        ret = salt.utils.json.loads(cmd_ret['stdout'], strict=False)

    except ValueError:
        raise CommandExecutionError('Unable to parse return data as Json.')

    return ret