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
CodePudding user response:
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
