I have a xml file which I want to update based on a value from a variable.
I would like to to something like this
$ns = @{ dts = 'www.microsoft.com/SqlServer/Dts' }
$xml2 = [XML](Get-Content "C:\Users\David\Documents\New.dtsx")
$xml2 |
Select-Xml -XPath "/dts:Executable/dts:Variables/dts:Variable[@dts:ObjectName = 'BATCH_JOB_ID']/dts:VariableValue" -Namespace $ns |
Select-Object -ExpandProperty Node |
Select-Object -ExpandProperty '#text' = "$BATCH_JOB_ID"
That is, I am trying to extract a specific XML element of interest and to update its ObjectName
attribute.
Why does this not work?
Another option is to use dot notation, which is what I prefer, but I do not know how to filter the attribute after this point:
$xml2.Executable.Variables.Variable
I have to use the filter @dts:ObjectName = 'BATCH_JOB_ID'
I can do like:
$xml2.Executable.Variables.Variable.VariableValue[0].'#text'
But instead of [0] I would like to write ObjectName = 'BATCH_JOB_ID
. Is that possible? How can I write something like:
$xml2.Executable.Variables.Variable.VariableValue[BATCH_JOB_ID].'#text'