Skip to content

WebConfigPropertyCollection

dscbot edited this page Jan 3, 2023 · 2 revisions

WebConfigPropertyCollection

Parameters

Parameter Attribute DataType Description Allowed Values
WebsitePath Key String Path to website location (IIS or WebAdministration format).
Filter Key String Filter used to locate property collection to update.
CollectionName Key String Name of the property collection to update.
ItemName Key String Name of the property collection item to update.
ItemKeyName Key String Name of the key of the property collection item to update.
ItemKeyValue Key String Value of the key of the property collection item to update.
ItemPropertyName Key String Name of the property of the property collection item to update.
ItemPropertyValue Write String Value of the property of the property collection item to update.
Ensure Write String Indicates if the property and value of the property collection item should be present or absent. Defaults to Present. Present, Absent

Description

The WebConfigPropertyCollection DSC resource is used to ensure the value of an identified property collection item's property in the web.config file.

Builds upon the deprecated WebConfigKeyValue resource to support all web.config elements that contain collections of child items.

Requirements

  • Target machine must be running Windows Server 2012 R2 or later.

Known issues

All issues are not listed here, see here for all open issues.

Examples

Example 1

Disables the HTTP TRACE method at the server level.

This example shows how to use the WebConfigPropertyCollection DSC resource for adding a configuration element. It will add an "add" element to the system.webServer/security/requestFiltering/verbs collection to disable the HTTP TRACE verb.

Configuration Sample_WebConfigPropertyCollection_Add
{
    param
    (
        # Target nodes to apply the configuration.
        [Parameter()]
        [String[]]
        $NodeName = 'localhost'
    )

    # Import the modules that define custom resources
    Import-DscResource -ModuleName WebAdministrationDsc

    Node $NodeName
    {
        WebConfigPropertyCollection "$($NodeName) - Disable HTTP TRACE method"
        {
            WebsitePath       = 'MACHINE/WEBROOT/APPHOST'
            Filter            = 'system.webServer/security/requestFiltering'
            CollectionName    = 'verbs'
            ItemName          = 'add'
            ItemKeyName       = 'verb'
            ItemKeyValue      = 'TRACE'
            ItemPropertyName  = 'allowed'
            ItemPropertyValue = 'false'
            Ensure            = 'Present'
        }
    }
}

Example 2

Removes disabling the HTTP TRACE method at the server level.

This example shows how to use the WebConfigPropertyCollection DSC resource for removing a configuration element. It will remove the "add" element from the system.webServer/security/requestFiltering/verbs collection (if present) for disabling the HTTP TRACE verb.

Configuration Sample_WebConfigPropertyCollection_Remove
{
    param
    (
        # Target nodes to apply the configuration.
        [Parameter()]
        [String[]]
        $NodeName = 'localhost'
    )

    # Import the modules that define custom resources
    Import-DscResource -ModuleName WebAdministrationDsc

    Node $NodeName
    {
        WebConfigPropertyCollection "$($NodeName) - Remove disabling HTTP TRACE method"
        {
            WebsitePath       = 'MACHINE/WEBROOT/APPHOST'
            Filter            = 'system.webServer/security/requestFiltering'
            CollectionName    = 'verbs'
            ItemName          = 'add'
            ItemKeyName       = 'verb'
            ItemKeyValue      = 'TRACE'
            ItemPropertyName  = 'allowed'
            ItemPropertyValue = 'false'
            Ensure            = 'Absent'
        }
    }
}