Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to alter multiple nodes in a DTSX xml file with powershell
    text
    copied!<p>I want to do the following: Select the <code>Configuration</code> nodes and, depending on the <code>ObjectName</code> value, change the <code>ConfigurationString</code> node value.</p> <p>The XML is the following:</p> <pre><code>&lt;DTS:Executable xmlns:DTS="www.microsoft.com/.." DTS:ExecutableType="SSIS.Package"&gt; &lt;DTS:Configuration&gt; &lt;DTS:Property DTS:Name="ConfigurationType"&gt;1&lt;/DTS:Property&gt; &lt;DTS:Property DTS:Name="ConfigurationString"&gt;change me&lt;/DTS:Property&gt; &lt;DTS:Property DTS:Name="ObjectName"&gt;Configuration_1&lt;/DTS:Property&gt; &lt;DTS:Property DTS:Name="DTSID"&gt;{..}&lt;/DTS:Property&gt; &lt;/DTS:Configuration&gt; &lt;DTS:Configuration&gt; &lt;DTS:Property DTS:Name="ConfigurationType"&gt;1&lt;/DTS:Property&gt; &lt;DTS:Property DTS:Name="ConfigurationString"&gt;me to please&lt;/DTS:Property&gt; &lt;DTS:Property DTS:Name="ObjectName"&gt;Configuration_2&lt;/DTS:Property&gt; &lt;DTS:Property DTS:Name="DTSID"&gt;{..}&lt;/DTS:Property&gt; &lt;/DTS:Configuration&gt; </code></pre> <p></p> <p>I had the following code to alter the ConfigurationString when there was only one instance of this type of node.</p> <pre><code>$item = [xml](Get-Content -Path($item_path)) $item.Executable.Configuration.Property | ? { $_.name -eq 'configurationstring'} | % { $_.'#text' = "text" } $item.Save( $item_path ) </code></pre> <p>I tried to add a condition at <code>? { $_.name -eq 'configurationstring'}</code> to check if the <code>ObjectName</code> was the desired one, but I couldn't get back to the <code>Configuration</code> node and change the <code>ConfigurationString</code> node value.</p> <p>I have also tried using the <code>SelectSingleNode</code> method, but it didn't work:</p> <pre><code>$item.SelectSingleNode("Executable/Configuration/Property[@ObjectName='Configuration_1']") | ? { $_.name -eq 'configurationstring'} | % { $_.'#text' = "test" } </code></pre> <p>Thanks and regards.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload