Skip to content

xWebConfigKeyValue

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

xWebConfigKeyValue

Important

This resource has been renamed in the latest release, see WebConfigKeyValue. 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)
ConfigSection Key String Config Section to be update AppSettings
Key Key String Key for AppSettings
Ensure Write String Indicates if the property and value should be present or absent. Defaults to Present. Present, Absent
Value Write String Value for AppSettings
IsAttribute Write Boolean If the given key value pair is for attribute, default is element

Description

NOTE: The xWebConfigKeyValue resource is deprecated and has been replaced by the xWebConfigProperty and xWebConfigPropertyCollection resources. It may be removed in a future release.

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

Adds an app setting WebsiteTitle to the configuration file of the website. This example shows how to use the xWebConfigKeyValue DSC resource for adding an extra key and value to appSettings. It will add a key WebSiteTitle with value to the configuration of the site specified.

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

        # Target website to which the key should be added.
        [String]   $WebsiteName = 'Default Web Site'
    )

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

    Node $NodeName
    {
        # Adds an extra app setting to the AppSettings section.
        xWebConfigKeyValue DefaultSite
        {
            Ensure        = 'Present'
            ConfigSection = 'AppSettings'
            Key           = 'WebsiteTitle'
            Value         = 'xWebAdministration DSC Examples'
            WebsitePath   = 'IIS:\Sites\' + $WebsiteName
        }
    }
}

Example 2

Removes an app setting WebsiteTitle from the configuration file of the website if present. This example shows how to use the xWebConfigKeyValue DSC resource for ensuring a key is not pressent in appSettings. It will remove a setting with key WebSiteTitle from the configuration of the site specified.

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

        # Target website from which the key should be removed.
        [String]   $WebsiteName = 'Default Web Site'
    )

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

    Node $NodeName
    {
        # Removes an extra app setting from the AppSettings section.
        xWebConfigKeyValue DefaultSite
        {
            Ensure        = 'Absent'
            ConfigSection = 'AppSettings'
            Key           = 'WebsiteTitle'
            Value         = 'xWebAdministration DSC Examples'
            WebsitePath   = 'IIS:\Sites\' + $WebsiteName
        }
    }
}