fix: preserve non-ASCII characters in CSV output#72
Open
1junh wants to merge 1 commit into
Open
Conversation
…Japanese) becoming '?'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When an Active Directory object name or trustee name contains non-ASCII characters (e.g. Japanese),
ADACLScan.ps1writes them as?in its CSV output (-Output CSV).Example, object
OU=テスト:Root cause
The four
Export-Csvcalls that write the standard CSV report ($global:ArrayAllACE | Export-Csv) don't specify-Encoding. The default-EncodingforExport-Csvdiffers by PowerShell version.References:
ASCIIhttps://learn.microsoft.com/powershell/module/microsoft.powershell.utility/export-csv?view=powershell-5.1
UTF8NoBOMhttps://learn.microsoft.com/powershell/module/microsoft.powershell.utility/export-csv?view=powershell-7.6
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 UTF8to the four standard-CSVExport-Csvcalls ($global:ArrayAllACE | Export-Csv) inADACLScan.ps1.UTF8is 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-PermCSVandWrite-DefSDPermCSValready 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.