Skip to content

Instantly share code, notes, and snippets.

@shiranGinige
Created February 15, 2016 00:02
Show Gist options
  • Save shiranGinige/c2ebd7f44e7f64187862 to your computer and use it in GitHub Desktop.
Save shiranGinige/c2ebd7f44e7f64187862 to your computer and use it in GitHub Desktop.
PS to update different configs
#set the value of this to your own db config
$myConnectionString = "Data Source=.;Initial Catalog=<<yourdatabase>>;Integrated Security=True";
$scriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$webConfig = $scriptDir + '\PeopleStreme.Api\Web.config'
$dbUpConfig = $scriptDir + '\PeopleStreme.Database\App.config'
$unitTestConfig = $scriptDir + '\Config\App.config'
Function updateConfig($webConfig)
{
Write-Host "Reading config" -ForegroundColor Green
$doc = (Get-Content $webConfig) -as [Xml]
$root = $doc.get_DocumentElement();
$activeConnection = $root.connectionStrings.SelectNodes("add");
$activeConnection.SetAttribute("connectionString", $myConnectionString);
Write-Host "Writing config" -ForegroundColor Green
$doc.Save($webConfig)
}
updateConfig($webConfig)
updateConfig($dbUpConfig)
updateConfig($unitTestConfig)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment