Home > Blockchain >  Change value of DisplayDiscountedPriceIfAny from FALSE to TRUE * powershell .exe.config file xml *
Change value of DisplayDiscountedPriceIfAny from FALSE to TRUE * powershell .exe.config file xml *

Time:10-28

Change value of DisplayDiscountedPriceIfAny from FALSE to TRUE powershell .exe.config file A script where I dont want to change the name, just the value from false to true.

# this is the part of the file I have to modify:

<setting name="DisplayDiscountedPriceIfAny" serializeAs="String">
    <value>False</value>
</setting>

# it should look like this when done:

<setting name="DisplayDiscountedPriceIfAny" serializeAs="String">
    <value>True</value>
</setting>

> I tried this but its obviously wrong

# Load the xml document
$filename = "C:\Users\files\HandheldOfflineSynchronization.exe.config"
$xmlDoc = New-Object xml
$xmlDoc.Load($filename)

# Select all applicable nodes
$nodes = $xmlDoc.SelectNodes('//appSettings/add[@key="key1"]')

# In each node, replace the value `Value1` with `NewValue`
foreach($node in $nodes){
  $node.value = $node.value.Replace('DisplayDiscountedPriceIfAny','False')
}

# Save the document

$xmlDoc.Save($filename)
<setting name="LogDated" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="Language" serializeAs="String">
        <value>cs</value>
            </setting>
            <setting name="LogMaxLevel" serializeAs="String">
                <value>Info</value>
            </setting>
            <setting name="ConnectionStringName" serializeAs="String">
                <value>Posybe</value>
            </setting>

CodePudding user response:

Based on your example you only have to specify '//setting' to select those nodes:

$nodes = $xmlDoc.SelectNodes('//setting')

Later in the loop you can assign the new value:

$node.value = 'false'
  • Related