Skip to content

fix: preserve non-ASCII characters in CSV output#72

Open
1junh wants to merge 1 commit into
canix1:masterfrom
1junh:fix/csv-utf8-encoding
Open

fix: preserve non-ASCII characters in CSV output#72
1junh wants to merge 1 commit into
canix1:masterfrom
1junh:fix/csv-utf8-encoding

Conversation

@1junh

@1junh 1junh commented Jul 13, 2026

Copy link
Copy Markdown

Summary

When an Active Directory object name or trustee name contains non-ASCII characters (e.g. Japanese), ADACLScan.ps1 writes them as ? in its CSV output (-Output CSV).

Example, object OU=テスト:

Before: "OU=???,DC=contoso,DC=com", ...
After:  "OU=テスト,DC=contoso,DC=com", ...

Root cause

The four Export-Csv calls that write the standard CSV report ($global:ArrayAllACE | Export-Csv) don't specify -Encoding. The default -Encoding for Export-Csv differs by PowerShell version.

References:

Because AD ACL Scanner runs on Windows PowerShell 5.1, the default is ASCII, which cannot represent non-ASCII characters, so they are written as ?.

Fix

Add -Encoding UTF8 to the four standard-CSV Export-Csv calls ($global:ArrayAllACE | Export-Csv) in ADACLScan.ps1. UTF8 is a valid value on both Windows PowerShell 5.1 and PowerShell 7+. This also matches the encoding already used by the script's other CSV writers (Write-PermCSV and Write-DefSDPermCSV already pass -Encoding UTF8). The CSVTEMPLATE, HTML, and EXCEL output paths are not affected.

Testing

Ran .\ADACLScan.ps1 -Base "OU=テスト,DC=contoso,DC=com" -Output CSV -OutputFolder . on Windows PowerShell 5.1 against an object whose name includes Japanese characters. Before the change the name was written as ?; after the change the CSV preserves the characters correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant