Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 编辑配置的值Powershell_Xml_Powershell - Fatal编程技术网

Xml 编辑配置的值Powershell

Xml 编辑配置的值Powershell,xml,powershell,Xml,Powershell,我熟悉powershell中的引用节点,但不完全确定如何编辑以下节点,因为每个值都没有唯一的标识符。我可以根据路径编辑这些值吗?每个路径引用一个SSIS变量。我只需要编辑configuredValue,但这是跨15个节点的。以下是这些节点的两个示例: <Configuration ConfiguredType="Property" Path="\Package.Variables[User::var1].Properties[Value]" ValueType="String"&

我熟悉powershell中的引用节点,但不完全确定如何编辑以下节点,因为每个值都没有唯一的标识符。我可以根据路径编辑这些值吗?每个路径引用一个SSIS变量。我只需要编辑configuredValue,但这是跨15个节点的。以下是这些节点的两个示例:

<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