Skip to content

WebConfigProperty

dscbot edited this page Jan 3, 2023 · 2 revisions

WebConfigProperty

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 to update.
PropertyName Key String Name of the property to update.
Ensure Write String Indicates if the property and value should be present or absent. Defaults to Present. Present, Absent
Value Write String Value of the property to update.

Description

The WebConfigProperty DSC resource is used to ensure the value of an identified property in the web.config file.

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 directory browsing in the default website.

This example shows how to use the WebConfigProperty DSC resource for setting a configuration property. It will set the value of the system.webServer/directoryBrowse enabled attribute to false in the Web.config file for the default website.

Configuration Sample_WebConfigProperty_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
    {
        WebConfigProperty "$($NodeName) - Ensure 'directory browsing' is set to disabled - Add"
        {
            WebsitePath  = 'IIS:\Sites\Default Web Site'
            Filter       = 'system.webServer/directoryBrowse'
            PropertyName = 'enabled'
            Value        = 'false'
            Ensure       = 'Present'
        }
    }
}

Example 2

Removes configuration of directory browsing in the default website.

This example shows how to use the WebConfigProperty DSC resource for removing a configuration property. It will remove the system.webServer/directoryBrowse enabled attribute (if present) in the Web.config file for the default website.

Configuration Sample_WebConfigProperty_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
    {
        WebConfigProperty "$($NodeName) - Ensure 'directory browsing' is set to disabled - Remove"
        {
            WebsitePath  = 'IIS:\Sites\Default Web Site'
            Filter       = 'system.webServer/directoryBrowse'
            PropertyName = 'enabled'
            Ensure       = 'Absent'
        }
    }
}