A
A
Artem Kiryanov2018-11-13 17:57:26
PowerShell
Artem Kiryanov, 2018-11-13 17:57:26

How to change value in config via Powershell?

There is a config, I need to change the values ​​of value in config by getting the value from a text file.
That is: in xml there is <add key="shopId" value="foo"/> and is a text file, it contains a value.
I either replace the entire file, or duplicate values ​​are written.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Kiryanov, 2018-11-13
@hacker342

Yes, you have achieved something.

[XML]$xml = Get-Content "путь до xml"
$xpath = "/configuration/appSettings/add[@value='5' and @key ='shopId']"
$nodes = $xml.SelectNodes($xpath)

foreach ($n in $nodes) {
    $n.value = "S013"
}

$xml.Save($xmlFile)

But in this variant, the change will occur if we have the value value = the last value $n.value
I think further.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question