0

I was using a Powershell script I found to help me rename a BizTalk application. The maps are stored in .btm files, and must have an XML byte order mark.

After running this script:

$configFiles = Get-ChildItem -Path "C:\MyCodePath" *.btm* -rec
foreach ($file in $configFiles)
{
    (Get-Content $file.PSPath) | 
    Foreach-Object { $_ -replace "oldstring", "newstring" } |
    Set-Content $file.PSPath
}

then I got build error: error btm1023: Exception Caught: There is no Unicode byte order mark. Cannot switch to Unicode.

NealWalters
  • 17,197
  • 42
  • 141
  • 251
  • `Set-Content -Encoding Unicode`, or use `Out-File`, which defaults to Unicode. – Ansgar Wiechers Jul 17 '18 at 22:03
  • Possible duplicate of [Powershell set-content and out-file what is the difference?](https://stackoverflow.com/q/10655788/1630171) – Ansgar Wiechers Jul 17 '18 at 23:00
  • But I wouldn't want to set the -Encoding Unicode for non-Unicode files. So should I test to see if it's Unicode or not and have two Set-Content statements under an IF Statement? – NealWalters Jul 18 '18 at 13:50
  • 1
    Then you need to check the encoding, e.g. like this : `(-join [char[]](Get-Content $file.PSPath -Encoding Byte -TotalCount 2)) -eq 'ÿþ'`. – Ansgar Wiechers Jul 18 '18 at 20:10

0 Answers0