Created
January 17, 2019 16:40
-
-
Save gavi/dcc14ffc60296bf61299fe42a65840d3 to your computer and use it in GitHub Desktop.
Add a connectionString to Web.config
This file contains hidden or 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 AddAttribute([System.Xml.XmlNode] $node, $name , $value){ | |
$attrib = $node.OwnerDocument.CreateAttribute($name) | |
$attrib.Value = $value | |
$node.Attributes.Append($attrib) | |
} | |
function AddConnectionString($webconfigFile, $name, $connectionString){ | |
[xml]$document = Get-Content $webconfigFile | |
$configElement = $document.SelectSingleNode("configuration") | |
$connectionStringsElement = $configElement.SelectSingleNode("connectionStrings") | |
[System.Xml.XmlNode]$add = $document.CreateElement("add") | |
AddAttribute $add "name" $name | |
AddAttribute $add "connectionString" $connectionString | |
$connectionStringsElement.AppendChild($add) | |
$document.Save($webconfigFile) | |
} | |
AddConnectionString C:\temp\2.3.48.1547065790761\api\Web.config "test" "testConnectionString" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment