I have a rather large XML file that I need to replace some connection strings within.
I use the following code to replace the strings:
$temp = Get-Content .\bigxmlfile.xml
$temp.replace("STRING1","STRING2") | out-file .\bigxmlfile.xml -force
This changes the strings just fine but for some reason ALWAYS ends up breaking the XML.
I'm having trouble figuring out why.
Best Answer
Out-File
is writing a Unicode file by default. Use-Encoding
to fix it:Alternatively, use
Set-Content
: