Advertisement
Guest User

PS script to output folder ACL's to CSV

a guest
Nov 15th, 2012
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $path = Read-Host "Enter the path you wish to check"
  2.  
  3. [Array] $list = "Path   Access Entity   Mode    Rights"
  4. [Array] $folders = Get-ChildItem -path $path -recurse | Where {$_.PSIsContainer}
  5.  
  6. ForEach ($folder in [Array] $folders)
  7. {
  8. [Array] $PSPath += (Convert-Path $folder.pspath)
  9. }
  10.  
  11. #Initialize While Loop, set $p to Array Size - 1
  12. $i=0
  13. $p = $PSPath.Count - 1
  14.  
  15. While ($i -le $P)
  16. {
  17. [Array] $acls += Get-Acl -Path $PSPath[$i] | Format-List
  18. $i += 1
  19. }
  20.  
  21. #Reset i to 0
  22. $i=0
  23.  
  24. Foreach($acl in $acls)
  25. {
  26.     ForEach($access in $acl.Access)
  27.     {
  28.     $path = $PSPath[$i]
  29.         ForEach($value in $access.IdentityReference.Value)
  30.         {
  31.         $list += ("$Path    $Value")
  32.         } #end ForEach
  33.     } #end ForEach
  34.     $list += ("--------------------------------------   --------------------------------")
  35. $i+=1  
  36. } #end ForEach
  37. $list | format-table | Out-File "c:\Users\$env:username\Documents\folderperms.csv"
  38.  
  39. Write-Host "File has been saved to c:\Users\$env:username\Documents\folderperms.csv"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement