Skip to the content.

Configuration Element Commands

Tips For the PowerShell newbies, you can then get the signature of all the configuration element commands via the following PowerShell command:

Get-Command -Noun ConfigurationElement | Get-Help

The Dsl.Configuration PowerShell module provides three commands to selectively edit individual element in XML configuration files:

Add-ConfigurationElement -TargetConfigurationFile <string[]> -XPath <string> -ElementName <string> [-Attribute <HashTable>] [-ConfigurationFileResolver <IConfigurationFileResolverStrategy[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

Remove-ConfigurationElement -TargetConfigurationFile <string[]> -XPath <string> [-ConfigurationFileResolver <IConfigurationFileResolverStrategy[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

Set-ConfigurationElement -TargetConfigurationFile <string[]> -XPath <string> [-Attribute <HashTable>] [-ConfigurationFileResolver <IConfigurationFileResolverStrategy[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

Where

The following excerpt provides a few usage samples of these commands:

Add-ConfigurationElement -TargetConfigurationFile global:clr4:machine.config `
  -XPath /configuration/appSettings `
  -ElementName add `
  -Attribute @{ key = 'setting' ; value = 'value' }

Remove-ConfigurationElement -TargetConfigurationFile global:biztalk.config `
   -XPath /configuration/element

Set-ConfigurationElement -TargetConfigurationFile global:clr4:32bits:machine.config `
   -XPath /configuration/element `
   -Attribute @{ '{urn:custom:namespace}attribute' = 'value' }

Caution! These commands are not idempotent as are Configuration Specification, that is to say that a command that completed successfully would fail if being executed again.

Remark Contrary to the Configuration Specification command, these commands will not perform any backup of the edited XML configuration files or create any inverse scripts capable of undoing all the changes that have actually been made.