Skip to content

Instantly share code, notes, and snippets.

@droogie
Created October 12, 2020 17:56
Show Gist options
  • Save droogie/2ce847380665fd16a731bf205b620575 to your computer and use it in GitHub Desktop.
Save droogie/2ce847380665fd16a731bf205b620575 to your computer and use it in GitHub Desktop.
recursively get directory ACLs and last modified date
$Items = (Get-ChildItem "C:\" -Recurse | Where { $_.PSIsContainer } | select fullname | %{$_.fullname.trim()})
$Path = "C:\temp\ACLs.csv"
$Table = @()
$Record = [ordered]@{
"Directory" = ""
"Owner" = ""
"FileSystemRights" = ""
"AccessControlType" = ""
"IdentityReference" = ""
"IsInherited" = ""
"InheritanceFlags" = ""
"PropogationFlags" = ""
"ModifiedDate" = ""
}
Foreach ($Item in $Items)
{
$ACL = (Get-Acl -Path $Item)
$LastWriteTime = (Get-Item $Item).LastWriteTime
$Record."Directory" = $ACL.path | %{$_.trimstart("Microsoft.PowerShell.Core\FileSystem::")}
$Record."Owner" = $ACL.Owner
Foreach ($SItem in $ACL.access)
{
$Record."FileSystemRights" = $SItem.FileSystemRights
$Record."AccessControlType" = $SItem.AccessControlType
$Record."IdentityReference" = $SItem.IdentityReference
$Record."IsInherited" = $SItem.IsInherited
$Record."InheritanceFlags" = $SItem.InheritanceFlags
$Record."PropogationFlags" = $SItem.PropagationFlags
$Record."ModifiedDate" = $LastWriteTime
$objRecord = New-Object PSObject -property $Record
$Table += $objrecord
}
}
$Table | Export-Csv -Path $Path -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment