I have been trying to develop a script in powershell that could update / append new attribute values ( do not change existing values ) separated by " , " up to 4 values.
The format of the file is
<configuration>
<appSettings>
<add key="servername" value="server1"/>
</appSettings>
</configuration>
Desired result is
<configuration>
<appSettings>
<add key="servername" value="server1,server2,server3,server3,server4"/>
</appSettings>
</configuration>
I can add new value but cannot retain the old one by below code
$file = "C:\Users\test\Desktop\server.exe.config"
$xml = [xml] (Get-Content $file)
$XPpath = "/configuration/appSettings/add[@key='servername']"
$nodes = $xml.SelectNodes($XPpath)
foreach ( $n in $nodes ) {
$n.value = $n.value = 'server2'
}
I read help documents / searched online but could not find any tip on how to achieve the desired result. Anything I am missing? Your help is appreciated.