Forked from jwcarroll/modifyConnectionStrings.ps1
Last active
August 29, 2015 14:23
-
-
Save hossambarakat/0530bbd47a32c7f8a8e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Set-ConnectionString{ | |
[CmdletBinding(SupportsShouldProcess=$True)] | |
Param( | |
[string]$fileName="app.config", | |
[string]$connectionStringName, | |
[string]$connectionString | |
) | |
$config = [xml](Get-Content -LiteralPath $fileName) | |
$config.Configuration.connectionStrings | |
$connStringElement = $config.SelectSingleNode("configuration/connectionStrings/add[@name='$connectionStringName']") | |
if($connStringElement) { | |
$connStringElement.connectionString = $connectionString | |
if($pscmdlet.ShouldProcess("$fileName","Modify app.config connection string")){ | |
Write-Host ("Updating app.config connection string {0} to be {1}" -f $connectionStringName, $connectionString) | |
$config.Save($fileName) | |
} | |
} | |
else{ | |
Write-Error "Unable to locate connection string named: $connectionStringName" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment