Guest User

Untitled

a guest
May 20th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. function getACLS ([string]$path, [int]$max, [int]$current)
  2. {
  3.  
  4. $dirs = Get-ChildItem -Path $path | Where { ($_.psIsContainer) }
  5. $acls = Get-Acl -Path $path
  6. $SECURITY = @()
  7. $i = 0
  8.  
  9. #Places the Security attributes in $security array
  10. foreach ($acl in $acls.Access)
  11. {
  12. if (($acl.identityreference -like "DOMAIN\*") <#-and ($acl.accesscontroltype -eq "allow")#> -and ($acl.IsInherited -eq 0))
  13. {
  14. $Security += "%" + $dir.FullName + '%' + $acl.identityreference + '%' + $acl.FileSystemRights + '%' + $acl.AccessControlType
  15. $i++
  16. }
  17. }
  18.  
  19. if ($current -lt $max) {
  20. if ($dirs) {
  21. foreach ($dir in $dirs) {
  22. $newPath = $dir.FullName
  23. getACLS $newPath $max ($current+1)
  24. }
  25. }
  26. } elseif ($current -eq $max ) {
  27. return ($Security)
  28. }
  29. }
  30.  
  31. $Path = "C:\"
  32. $Max = 2
  33. $current = 0
  34. $Array = @()
  35.  
  36.  
  37.  
  38. while($Max -gt $current)
  39. {
  40. $test += GetAcls $Path $Max $current
  41. $Max--
  42. }
  43.  
  44. $i = 0
  45. $Hash = New-Object System.Object
  46.  
  47. foreach($line in $test)
  48. {
  49. $temp = $line.Split('%')
  50. $Hash = New-Object System.Object
  51. $Hash | Add-Member -type NoteProperty -name Directory -value $temp[1]
  52. $Hash | Add-Member -type NoteProperty -name Group -value $temp[2]
  53. $Hash | Add-Member -type NoteProperty -name Rights -value $temp[3]
  54. $Hash | Add-Member -type NoteProperty -name Access -value $temp[4]
  55.  
  56. $array += $Hash
  57. }
Add Comment
Please, Sign In to add comment