Skip to content

Instantly share code, notes, and snippets.

@shiranGinige
Last active February 1, 2016 03:08
Show Gist options
  • Save shiranGinige/1eb3ff34437350eef805 to your computer and use it in GitHub Desktop.
Save shiranGinige/1eb3ff34437350eef805 to your computer and use it in GitHub Desktop.
Power-shell to update connection strings
#set the value of this to your own db config
$myConnectionString = "Data Source=.;Initial Catalog=<Database>;Integrated Security=True";
$webConfig = '.\Api\Web.config'
$dbUpConfig = '.\Database\App.config'
$unitTestConfig = '.\Test\App.config'
Function updateConfig($config)
{
$doc = (Get-Content $config) -as [Xml]
$root = $doc.get_DocumentElement();
$activeConnection = $root.connectionStrings.SelectNodes("add");
$activeConnection.SetAttribute("connectionString", $myConnectionString);
$doc.Save($config)
}
updateConfig($webConfig)
updateConfig($dbUpConfig)
updateConfig($unitTestConfig)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment