Skip to content

Instantly share code, notes, and snippets.

@nickadam
Created July 26, 2019 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickadam/87686674310c131fee34939f141d6617 to your computer and use it in GitHub Desktop.
Save nickadam/87686674310c131fee34939f141d6617 to your computer and use it in GitHub Desktop.
List Acls
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