Created
July 26, 2019 15:24
-
-
Save nickadam/87686674310c131fee34939f141d6617 to your computer and use it in GitHub Desktop.
List Acls
This file contains 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
function List-Acls { | |
param ( | |
$Path, | |
$Depth | |
) | |
$Depth = $Depth - 1 | |
Get-ChildItem $Path | ForEach-Object{ | |
$FullName = $_.FullName | |
$FilePath = $_.FullName -replace "^[^$]+\$\\" | |
$FileOrFolder = "File" | |
if($_.PSIsContainer){ | |
$FileOrFolder = "Folder" | |
} | |
$Acl = Get-Acl $_.FullName | |
[PSCustomObject]@{ | |
"FilePath" = $FilePath; | |
"Type" = $FileOrFolder; | |
"Acl" = "Owner"; | |
"FileSystemRights" = ""; | |
"AccessControlType" = ""; | |
"IdentityReference" = $Acl.Owner; | |
"IsInherited" = ""; | |
"InheritanceFlags" = ""; | |
"PropagationFlags" = ""; | |
} | |
$Acl | ForEach-Object { | |
$_.Access | ForEach-Object{ | |
[PSCustomObject]@{ | |
"FilePath" = $FilePath; | |
"Type" = $FileOrFolder; | |
"Acl" = "Access"; | |
"FileSystemRights" = $_.FileSystemRights; | |
"AccessControlType" = $_.AccessControlType; | |
"IdentityReference" = $_.IdentityReference; | |
"IsInherited" = $_.IsInherited; | |
"InheritanceFlags" = $_.InheritanceFlags; | |
"PropagationFlags" = $_.PropagationFlags; | |
} | |
} | |
} | |
if(($Depth -ge 0) -and ($FileOrFolder -eq "Folder")){ | |
List-Acls -Path $FullName -Depth $Depth | |
} | |
} | |
} | |
$Path = "\\server\share" | |
$Depth = 2; | |
List-Acls -Path $Path -Depth $Depth | Export-Csv -NoTypeInformation "Permissions.csv" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment