In terms of character encoding,
Set-Contentdefaults to system's default code page. When in doubt, use an explicit encoding, such as-Encode UTF8.The above assumes that the XML element in question is on a single line. If it isn't, things get more complicated: while you can use
Get-Content -Raw(PowerShell v3+) to read the entire input file at once,Set-Contentwill add an extra newline to the output; also, you'd have to adapt the regex passed to-replaceabove to account for line-spanning whitespace.- Matt's helpful answerMatt's helpful answer shows a more robust way of handling the value substitution, using proper XML parsing via the
[xml]type (fully qualified name:System.Xml.XmlDocument).
- Matt's helpful answerMatt's helpful answer shows a more robust way of handling the value substitution, using proper XML parsing via the