I have multiple config.xml files and I want to iterate through them all with the following:
-
nodes to be updated with the same value ‘Someones Account Details’
This element appears multiple times in all docs -
Using variables, replace repeated strings values.
Example of config attached – HOW DO I ATTACH AN EXAMPLE OR PASTE???
Here is the powershell code so far:
$path=“C:\Users\Bex\Documents\Client Projects\QA Refresh\RTI”
$node1=“/RTIAgent/Instructions/Instruction/HostAccount”
Get-ChildItem -Path $path -recurse | ForEach-Object {
$configFile = [ xml ](Get-Content $_.fullname)
#rites out all the values of the specified node
#$configFile.RTIAgent.Instructions.Instruction.HostAccount
Select-Xml -xml $configFile -XPath ‘//HostAccount’ |
ForEach-Object {$.Node.‘#text’ = ‘some other new Account Details’}
$configFile.Save($.fullname)
}
read-host “Script Complete - Press ENTER to exit”
It does actually update the HostAccount node, but also throws an error message:
Exception setting “#text”: “The property ‘#text’ cannot be found on this object.
Verify that the property exists and can be set.”
At C:\Users\Bex\Documents\Client Projects\QA Refresh\Dataload\Update RTI Config
Files.ps1:10 char:17
- ForEach-Object {$_.Node.‘#text’ = ‘some other new Account Details’}
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (
, SetValueInvocationException
- FullyQualifiedErrorId : ExceptionWhenSetting
- CategoryInfo : NotSpecified: (
Why does it throw this error if it works? And also, how can I use the variable rather than specify the xml structure.
And finally, how can I update the AgentVariables (I want to update the text using -replace as the element names will change? (so search for ‘MyDatabase’ and ‘StagingDatabaseName’ as opposed to the node names)
Thank you all