我想要执行以下操作:选择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