Eoin2211
Eoin2211

Reputation: 911

Output Array With UTF8 Encoding

I am running a powershell script which pulls a listing from Active Directory and writes to a CSV file. Special characters such as ó are being written as a '?' even though they are correct in Active Directory. Can I enforce UTF8 encoding?

Relevant Code:

$array | Select-Object Username, GivenName, Surname, Name, EmailAddress, Department, Title, ManagerName | Export-Csv -Path $csvoutput -NoTypeInformation

Upvotes: 0

Views: 1254

Answers (1)

DocZerø
DocZerø

Reputation: 8567

Export-CSV has a parameter -Encoding, that specifies the encoding for the exported CSV file. The default value is ASCII in PowerShell 5, or utf8NoBOM in PowerShell 7.

Assuming you're using PowerShell 5, your code would be:

$array | 
    Select-Object Username, GivenName, Surname, Name, EmailAddress, Department, Title, ManagerName | 
    Export-Csv -Path $csvoutput -NoTypeInformation -Encoding UTF8

Upvotes: 1

Related Questions