unreadable output file in powershell

If you redirect a not-completly-string output (like a spfile) to a file in powershell, you may not see the same in the file as in the output

  • without redirection

    PS C:\> Select-String "compatible" .\spfileDB01.ora
    spfileDB01.ora:13:*.compatible='11.2.0.4.0'
  • with redirection

    PS> Select-String "compatible" .\spfileDB01.ora > compatible.txt
    PS> vim -b .\compatible.txt
    ÿþ^M^@
    ^@s^@p^@f^@i^@l^@e^@D^@B^@0^@0^@1^@.^@o^@r^@a^@:^@1^@3^@:^@*^@.^@c^@o^@m^@p^@a^@t^@i^@b^@l^@e^@=^@'^@1^@1^@.^@2^@.^@0^@.^@4^@.^@0^@'^@^M^@
    ^@
  • With redirection and conversion to ascii

    PS> Select-String "compatible" .\spfileDB01.ora |
    Out-File -Encoding ASCII .\compatible.txt

    PS> vim .\compatible.txt

    spfileDB01.ora:13:*.compatible='11.2.0.4.0'

With Out-File (instead of >), you can specify the encoding, which does the trick

1 thought on “unreadable output file in powershell

Comments are closed.