What\'s the easiest way to convert XML from UTF16 to a UTF8 encoded file?
Try this solution that uses a XmlWriter:
$encoding="UTF-8" # most encoding should work
$files = get-ChildItem "*.xml"
foreach ( $file in $files )
{
[xml] $xmlDoc = get-content $file
$xmlDoc.xml = $($xmlDoc.CreateXmlDeclaration("1.0",$encoding,"")).Value
$xmlDoc.save($file.FullName)
}
You may want to look at XMLDocument for more explanation on CreateXmlDeclaration.