Get-EffectiveAccessRecurse.ps1 815 B

1234567891011121314151617181920212223242526272829
  1. param(
  2. $Path,
  3. $Account=$env:USERNAME,
  4. [Int]
  5. $Depth=99
  6. )
  7. foreach ($module in @("NTFSSecurity")){
  8. if (-not (Get-Module -ListAvailable -Name $module)) {
  9. Install-Module $module -Scope CurrentUser
  10. }
  11. if (-not (Get-Module $module)) {
  12. Import-Module $module
  13. }
  14. }
  15. Get-ChildItem -Recurse -Depth $Depth -Directory $path | ForEach-Object {
  16. $rights = Get-NTFSEffectiveAccess -Account $Account -Path $_.FullName
  17. [PSCustomObject]@{
  18. Path=$_.FullName
  19. AccessRights=$rights.AccessRights
  20. InheritanceFlags=$rights.InheritanceFlags
  21. AccessControlType=$rights.AccessControlType
  22. InheritedFrom=$rights.InheritedFrom
  23. InheritanceEnabled=$rights.InheritanceEnabled
  24. Account=$Account
  25. Owner=(Get-Acl $_.FullName).Owner
  26. }
  27. }