Having the following app.config:
<configuration>
<appSettings>
<add key="filepath" value="D:\Data" />
<add key="node2" value="..." />
...
</appSettings>
</configuration>
I want to replace the setting that has 'filepath' key with a new value (by replacing 'D:\Data..' in this case). The new value should be passed as a parameter to the powershell script. Thanks
Update based on the comment:
$xml = [xml]'<configuration>
<appSettings>
<add key="filepath" value="D:\Data" />
<add key="filename" value="test.log" />
</appSettings>
</configuration>'
$xml.configuration.appSettings.add | foreach { if ($_.key -eq 'filepath') { $_.value = "C:\Data" } }
$xml.Save("C:\dell\NewApp.config")
===========================================================================================
$xml = [xml]'<configuration>
<appSettings>
<add key="filepath" value="D:\Data" />
</appSettings>
</configuration>'
$xml.configuration.appSettings.add.value = "C:\Data"
$xml.Save("NewApp.config")
or
$xml = [xml](Get-Content App.config)
$xml.configuration.appSettings.add.value = "C:\Data"
$xml.Save("NewApp.Config")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With