Powershell Remedy ARQ files, possible encoding problem

I'm having problems editing a file. This is an .ARQ file created by BMC Remedy, a ticketing system.

I can open it in notepad ++, edit it and everything is in order. However, when I try to use PowerShell to edit it, everything becomes messy. Although visually it looks the same, the application does not read it in the same way. Here are some tests I did to try to figure out what was wrong.

Test 1

get-content monitor.arq | set-content monitor2.arq

Result

Length Name
------ ----
  3578 monitor.arq
  3585 monitor2.arq 

They are mainly of different sizes, and monitor2.arq does not work, as monitor.arq does, visually in notepad ++ they are identical

Test 2

I thought it was an encoding problem, so I tried this.

$code = @("Unicode", "UTF7", "UTF8", "UTF32", "ASCII", "BigEndianUnicode", "Default", "OEM")
for ($a = 0; $a -lt $code.count; $a++) {
    Get-Content .\monitor.arq | Out-File -Encoding $code[$a] -FilePath ".\monitor$a-$($code[$a]).arq"
}

Result

Length Name                         
------ ----                         
  3578 monitor.arq                  
  7172 monitor0-Unicode.arq         
  4911 monitor1-UTF7.arq            
  3596 monitor2-UTF8.arq            
 14344 monitor3-UTF32.arq           
  3585 monitor4-ASCII.arq           
  7172 monitor5-BigEndianUnicode.arq
  3585 monitor6-Default.arq         
  3585 monitor7-OEM.arq  

, , , , , .

( , ), .

++ ANSI

, , ASCII

, , - , .

.

( )

$content1=gc -Encoding byte monitor.arq
[System.Text.Encoding]::ASCII.GetString($content1) | out-file -Encoding ascii -FilePath .\monitor2.arq
$content2=gc -Encoding byte monitor2.arq
Compare-Object $content1 $content2

, , .

InputObject SideIndicator
----------- -------------
         63 =>           
         63 =>           
         63 =>           
         63 =>           
         13 =>           
         10 =>           
        201 <=           
        233 <=           
        233 <=           
        201 <=           

13 10, , , , , , , , - , END ( BMC)

, , , 201 233 63. , ? [], , 63, 201, , 203.

, . , , ASCII, , , , .

$content1=gc -Encoding byte monitor.arq
[System.Text.Encoding]::default.GetString($content1) | out-file -Encoding default -FilePath .\monitor2.arq
$content2=gc -Encoding byte monitor2.arq
Compare-Object $content1 $content2 | format-table -AutoSize

, , ,

+4
1
$content1=gc -Encoding byte monitor.arq
[System.Text.Encoding]::default.GetString($content1) | out-file -Encoding default -FilePath .\monitor2.arq
$content2=gc -Encoding byte monitor2.arq
Compare-Object $content1 $content2 | format-table -AutoSize
0

Source: https://habr.com/ru/post/1616260/


All Articles