1

I have an array of objects in Powershell. It was working, but now when I do an Export-Csv on the array, it property and value names are transformed like:

Account_No -> +ACI-Account+AF8-No+ACI-

Does anyone know why it is doing this?

Thanks

I am using PS 5.1, and the command is:

$rowsWithErrs | Export-Csv -Path $rowErrCsvPath -NoTypeInformation -Encoding UTF7
3
  • 1
    What version of PowerShell are you using (and if PowerShell Core, on what OS)? What is the exact Export-CSV command that you are using? Commented Apr 29, 2019 at 14:48
  • What system requires utf7? Commented Apr 29, 2019 at 16:38
  • We're receiving CSV files from external sources, and we need to send them back in the same encoding. Commented Apr 29, 2019 at 17:00

1 Answer 1

1

It looks like there isn't anything wrong with what you are doing. Everything is getting sent out in the format that you are expecting.

The only problem is that the application that you are using to view your data is not using the same encoding that was used to write the data.

The extra characters are what you see when interpreting text as UTF8 or something similar or compatible with UTF8 (which is the standard for most systems) instead of UTF7 when the text was encoded as UTF7.

example

> "Account_No" | Out-File -FilePath test.txt -Encoding UTF7
> Get-Content test.txt -Encoding UTF8
Account+AF8-No
> Get-Content test.txt -Encoding UTF7
Account_No

if reading csv data in Powershell you can do the following

> $csv = Import-Csv -FilePath $filepath -Encoding UTF7

if reading csv data in Excel, on the data tab select From Text/CSV at the top of the import window select File Origin 65000: Unicode (UTF-7)

File Origin select

For other applications like VS Code or Notepad++ you may be out of luck if you want to view the data there because it looks like they do not support UTF-7 encoding.

Sign up to request clarification or add additional context in comments.

6 Comments

Constraints of the system. I would much prefer to use UTF8. Is there any way to work around this?
@Sako73 How are you viewing the text? The problem is that you are decoding the text as UTF8 instead of UTF7. The default for most things like Notepad++ is UTF8, and it's difficult to set it to use UTF7. In Notepad++ UTF7 isn't even an encoding option that I can find.
I'm viewing it in Visual Studio Code and Excel, and it appears the same in both. I tried reloading the file with the 1252 encoding, and it is still the same. It doesn't appear to be the viewer, it appears that the extra characters are being added to the text when the file is written out.
If I export it UTF8, it works great, but the system expects files in UTF7.
@Sako73 The encoding that you want in Excel and VS Code is 65000: Unicode (UTF-7)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.