Replace app.config item node value in powershell Replace app.config item node value in powershell powershell powershell

Replace app.config item node value in powershell


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")

===========================================================================================

OLD ANSWER

$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")