powershell weirdly encodes ampersands when I try to set the value to an xml attribute
build-script, powershell, powershell-2.0, xml
Solution
Have you try to `decode` your connection string first? Here is sample:
[System.Reflection.Assembly]::LoadWithPartialName("System.web")
[System.Web.HttpUtility]::HtmlDecode(""")
Problem
In my build script, I have a helper powershell function as below: ``` function set-connectionstring { param($path, $name, $value) $settings = [xml](get-content $path) $setting = $settings.configuration.connectionStrings.add | where { $_.name -eq $name } $setting.connectionString = "$value" $setting.providerName = "System.Data.SqlClient" $resolvedPath = resolve-path($path) $settings.save($resolvedPath) } ``` It works great except that when I try to set the value, it encodes ampersands weirdly. Here is the issue: Inside my connection string I have `"` value. This should be perfectly valid. However, my above code transforms this into `"` which is totally unreasonable. Do you have any idea I can solve this problem?