How do I read/write App.config settings with PowerShell?

Robin picture Robin · May 16, 2009 · Viewed 26.7k times · Source

I'd like to use PowerShell as part of our automated build process to update an App.config file while deploying into our test environment. How can I do this?

Answer

Shay Levy picture Shay Levy · May 16, 2009

The code can be much more shorter (based on Robin's app.config):

$appConfig = [xml](cat D:\temp\App.config)
$appConfig.configuration.connectionStrings.add | foreach {
    $_.connectionString = "your connection string"
}

$appConfig.Save("D:\temp\App.config")