Created
October 12, 2020 17:56
-
-
Save droogie/2ce847380665fd16a731bf205b620575 to your computer and use it in GitHub Desktop.
recursively get directory ACLs and last modified date
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
$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