Beta

Convert icacls.exe output to json string

Description:

A colleague asked you for a function called ConvertTo-iCaclsOutPutObj to convert the output from icacls.exe to an json string. The function should have the path of the file or folder (-Path) and the output of the icacls.exe (-iCaclsOutPut) as input parameters. The return value should be a compressed json string in the format {"Path":"PATH","ACL":["PERMISSION1","PERMISSION2"]}.

Example of an icacls.exe output:

C:\Temp NT AUTHORITY\SYSTEM:(I)(OI)(CI)(F)
        BUILTIN\Administrators:(I)(OI)(CI)(F)
        BUILTIN\Users:(I)(OI)(CI)(RX)
        BUILTIN\Users:(I)(CI)(AD)
        BUILTIN\Users:(I)(CI)(WD)
        CREATOR OWNER:(I)(OI)(CI)(IO)(F)

Successfully processed 1 files; Failed processing 0 files

Example of the expected json string:

{"Path":"C:\\Temp","ACL":["NT AUTHORITY\\SYSTEM:(I)(OI)(CI)(F)","BUILTIN\\Administrators:(I)(OI)(CI)(F)","BUILTIN\\Users:(I)(OI)(CI)(RX)","BUILTIN\\Users:(I)(CI)(AD)","BUILTIN\\Users:(I)(CI)(WD)","CREATOR OWNER:(I)(OI)(CI)(IO)(F)"]}








Full example:

[System.String]$Path = 'C:\Temp'
[System.String]$iCaclsOutPut = icacls.exe $Path  | Out-String
<#
$iCaclsOutPut = @'
C:\Temp NT AUTHORITY\SYSTEM:(I)(OI)(CI)(F)
        BUILTIN\Administrators:(I)(OI)(CI)(F)
        BUILTIN\Users:(I)(OI)(CI)(RX)
        BUILTIN\Users:(I)(CI)(AD)
        BUILTIN\Users:(I)(CI)(WD)
        CREATOR OWNER:(I)(OI)(CI)(IO)(F)

Successfully processed 1 files; Failed processing 0 files
'@
#>

ConvertTo-iCaclsOutPutObj -Path $Path -iCaclsOutPut $iCaclsOutPut
<#
{"Path":"C:\\Temp","ACL":["NT AUTHORITY\\SYSTEM:(I)(OI)(CI)(F)","BUILTIN\\Administrators:(I)(OI)(CI)(F)","BUILTIN\\Users:(I)(OI)(CI)(RX)","BUILTIN\\Users:(I)(CI)(AD)","BUILTIN\\Users:(I)(CI)(WD)","CREATOR OWNER:(I)(OI)(CI)(IO)(F)"]}
#>
JSON
Fundamentals

Stats:

CreatedMar 30, 2020
PublishedMar 30, 2020
Warriors Trained70
Total Skips1
Total Code Submissions23
Total Times Completed11
PowerShell Completions11
Total Stars0
% of votes with a positive feedback rating60% of 5
Total "Very Satisfied" Votes2
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes1
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • pgra Avatar
Ad