Xml 编辑配置的值Powershell
我熟悉powershell中的引用节点,但不完全确定如何编辑以下节点,因为每个值都没有唯一的标识符。我可以根据路径编辑这些值吗?每个路径引用一个SSIS变量。我只需要编辑configuredValue,但这是跨15个节点的。以下是这些节点的两个示例:Xml 编辑配置的值Powershell,xml,powershell,Xml,Powershell,我熟悉powershell中的引用节点,但不完全确定如何编辑以下节点,因为每个值都没有唯一的标识符。我可以根据路径编辑这些值吗?每个路径引用一个SSIS变量。我只需要编辑configuredValue,但这是跨15个节点的。以下是这些节点的两个示例: <Configuration ConfiguredType="Property" Path="\Package.Variables[User::var1].Properties[Value]" ValueType="String"&
<Configuration ConfiguredType="Property" Path="\Package.Variables[User::var1].Properties[Value]"
ValueType="String">
<ConfiguredValue>SomeValue</ConfiguredValue>
</Configuration>
<Configuration ConfiguredType="Property" Path="\Package.Variables[User::var2].Properties[Value]"
ValueType="String">
<ConfiguredValue>AnotherValue</ConfiguredValue>
</Configuration>
有可能:
# xml object to use in example
[xml]$xml = @"
<root>
<Configuration ConfiguredType="Property" Path="\Package.Variables[User::var1].Properties[Value]"
ValueType="String">
<ConfiguredValue>SomeValue</ConfiguredValue>
</Configuration>
<Configuration ConfiguredType="Property" Path="\Package.Variables[User::var2].Properties[Value]"
ValueType="String">
<ConfiguredValue>AnotherValue</ConfiguredValue>
</Configuration>
</root>
"@
这太有用了!感谢您的快速回复+1.
# xml object to use in example
[xml]$xml = @"
<root>
<Configuration ConfiguredType="Property" Path="\Package.Variables[User::var1].Properties[Value]"
ValueType="String">
<ConfiguredValue>SomeValue</ConfiguredValue>
</Configuration>
<Configuration ConfiguredType="Property" Path="\Package.Variables[User::var2].Properties[Value]"
ValueType="String">
<ConfiguredValue>AnotherValue</ConfiguredValue>
</Configuration>
</root>
"@
# standard node dot-indexing, before
$xml.root.Configuration
# ConfiguredType Path ValueType ConfiguredValue
# -------------- ---- --------- ---------------
# Property \Package.Variables[User::var1].Properties[Value] String SomeValue
# Property \Package.Variables[User::var2].Properties[Value] String AnotherValue
# change the value based on Path
($xml.root.Configuration | Where-Object {$_.Path -like "*var1*"}).ConfiguredValue = "newValue"
# standard node dot-indexing, after
$xml.root.Configuration
# ConfiguredType Path ValueType ConfiguredValue
# -------------- ---- --------- ---------------
# Property \Package.Variables[User::var1].Properties[Value] String newValue
# Property \Package.Variables[User::var2].Properties[Value] String AnotherValue