Skip to content

xWebConfigProperty

Johan Ljunggren edited this page Dec 6, 2023 · 2 revisions

xWebConfigProperty

Important

This resource has been renamed in the latest release, see WebConfigProperty. Bug fixes and new functionality will only be added to the renamed resource.

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 xWebConfigProperty 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 xWebConfigProperty 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_xWebConfigProperty_Add
{
    param
    (
        # Target nodes to apply the configuration.
        [Parameter()]
        [String[]]
        $NodeName = 'localhost'
    )

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

    Node $NodeName
    {
        xWebConfigProperty "$($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 xWebConfigProperty 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_xWebConfigProperty_Remove
{
    param
    (
        # Target nodes to apply the configuration.
        [Parameter()]
        [String[]]
        $NodeName = 'localhost'
    )

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

    Node $NodeName
    {
        xWebConfigProperty "$($NodeName) - Ensure 'directory browsing' is set to disabled - Remove"
        {
            WebsitePath  = 'IIS:\Sites\Default Web Site'
            Filter       = 'system.webServer/directoryBrowse'
            PropertyName = 'enabled'
            Ensure       = 'Absent'
        }
    }
}