我想做以下事情:选择Configuration节点,然后根据ObjectName值更改ConfigurationString节点值。
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" }
谢谢并恭祝安康。