Configuration Element Commands
Tips For the
PowerShellnewbies, you can then get the signature of all the configuration element commands via the followingPowerShellcommand: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
-
TargetConfigurationFileis a list of targetXMLconfiguration file monikers, see Configuration File Monikers and Resolvers; -
XPathis either the location of the element to remove or set, or the location of the parent of the element to add; -
ElementNameis the name of the element to add; -
Attributeis the attributes and their values to either add to or set for the targeted element; -
ConfigurationFileResolveris an ordered list of object instances of classes implementing the IConfigurationFileResolverStrategy interface that will participate in the resolution of target configuration file monikers, see Configuration File Monikers and Resolvers.
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
XMLconfiguration files or create any inverse scripts capable of undoing all the changes that have actually been made.