poweshell sc with arabic support

Imran Syed 21 Reputation points
2020-12-06T05:23:58.703+00:00

I am trying to convert xml file into UTF8 unicode. this xml contains arabic characters which appear as ???????? after conversion.

can anyone support please how to convert file to UTF without loosing arabic

when i convert it to usinng -ecoding UTF8 , still converts as UTF8-BOM

this is my syntax

gc e:\testxml\abc.xml | sc E:\testxml\upload.xml

it converts file to UTF8 but arabic appears as ?????????

Thanks for your support

Imran

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,344 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 44,541 Reputation points
    2020-12-06T16:27:52.687+00:00

    Try this if you want to write a UTF file with no BOM: using-powershell-to-write-a-file-in-utf-8-without-the-bom

    $MyRawString = Get-Content -Raw c:\junk\bom.txt  
    $Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False  
    [System.IO.File]::WriteAllLines("c:\junk\NewNoBOM.txt", $MyRawString, $Utf8NoBomEncoding)  
    

    I used the same content as MotoX80:45436-bom.txt
    I used a very handy tool (HxD: hxd) to examine the two files and exported the results from HxD as "Editor view". The BOM isn't present on the file EXPORT-NewNoBOM.
    45494-export-bom.txt
    45330-export-newnobom.txt

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. MotoX80 31,556 Reputation points
    2020-12-06T13:28:16.697+00:00

    What is the encoding of the source file? Wouldn't the file already have to be in UTF8 format in order for Powershell to read the characters in correctly?

    Does notepad/Powershell read the file correctly? Have you tried specifying different input encoding?

    45449-capture.jpg

    See also: https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/get-text-file-encoding

    0 comments No comments

  2. Imran Syed 21 Reputation points
    2020-12-08T06:12:26.187+00:00

    thanks alot RichMatheisen-8856 for taking time.
    meanwhile another challange came across where Excel 365 VBA giving error for Powershell to run and giving permission denied error.
    now struggling with that error

    thanks for your support

    0 comments No comments