我想要執行以下操作:選擇Configuration
節點,並根據ObjectName
值更改ConfigurationString
節點值。如何使用PowerShell更改DTSX xml文件中的多個節點
的XML如下:
<DTS:Executable xmlns:DTS="www.microsoft.com/.." DTS:ExecutableType="SSIS.Package">
<DTS:Configuration>
<DTS:Property DTS:Name="ConfigurationType">1</DTS:Property>
<DTS:Property DTS:Name="ConfigurationString">change me</DTS:Property>
<DTS:Property DTS:Name="ObjectName">Configuration_1</DTS:Property>
<DTS:Property DTS:Name="DTSID">{..}</DTS:Property>
</DTS:Configuration>
<DTS:Configuration>
<DTS:Property DTS:Name="ConfigurationType">1</DTS:Property>
<DTS:Property DTS:Name="ConfigurationString">me to please</DTS:Property>
<DTS:Property DTS:Name="ObjectName">Configuration_2</DTS:Property>
<DTS:Property DTS:Name="DTSID">{..}</DTS:Property>
</DTS:Configuration>
我有下面的代碼改變ConfigurationString當有這種類型的節點只有一個實例。
$item = [xml](Get-Content -Path($item_path))
$item.Executable.Configuration.Property | ? { $_.name -eq 'configurationstring'} | % { $_.'#text' = "text" }
$item.Save($item_path)
我試圖在? { $_.name -eq 'configurationstring'}
添加一個條件,以檢查是否ObjectName
是所需的,但我不能讓回Configuration
節點,改變ConfigurationString
節點值。
我已經使用SelectSingleNode
方法也試過,但沒有奏效:
$item.SelectSingleNode("Executable/Configuration/Property[@ObjectName='Configuration_1']") | ? { $_.name -eq 'configurationstring'} | % { $_.'#text' = "test" }
感謝和問候。
謝謝你的回答,但問題仍然存在。如果我只用一個'DTS:Configuration'來使用你的代碼,它就可以工作,但是當有+1'DTS:Configuration'時,它什麼也不做。 – Bparra
再試一次,它使用的是V3的功能,但您使用的是v2 –
現在,它的工作原理,謝謝! – Bparra