Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. #Prompt for file path to file share
  2. $SharePath = "\servershare" # read-host "prompt"
  3.  
  4. #Get a list of first-level sub-folders within the fileshare and put it into the Folders variable
  5. $Folders = GCI $SharePath* | where {$_.psiscontainer -eq $true}
  6.  
  7. $i = 1
  8.  
  9. #Declare the Excel variables
  10. $excel = new-object -comobject excel.application
  11. $excel.visible = $true
  12. $excel = $excel.workbooks.add()
  13. $sheet = $excel.sheets.item(1)
  14. $introw = 2
  15. #$workbook = $sheet.usedrange
  16.  
  17. #Prompt for file path to export report(s)
  18. #$exportpath = "\servershare" # read-host "prompt"
  19.  
  20. #For each folder on that list, do the following...
  21. foreach ($Folder in $Folders){
  22. #Get full ACL list and put it into the ACLs variable
  23. $ACLs = get-acl $Folder.fullname | ForEach-Object {$_.Access}
  24. #Name the worksheet the name of the folder
  25. $CurrentSheet = $excel.sheets.item('sheet' + $i)
  26. $CurrentSheet.Activate
  27. $CurrentSheet.name = $Folder.pschildname
  28. #$sheet.Name = $Folder.pschildname
  29. #For each ACL on that list, do the following...
  30. Foreach ($ACL in $ACLs){
  31. #Set headers in excel file
  32. $sheet.Cells.Item(1,1).FormulaLocal = "Folder Path"
  33. $sheet.Cells.Item(1,2).FormulaLocal = "Group/User"
  34. $sheet.Cells.Item(1,3).FormulaLocal = "Allow/Deny"
  35. $sheet.Cells.Item(1,4).FormulaLocal = "Level of Permissions"
  36. #Insert Data
  37. $sheet.Cells.Item($intRow, 1) = $Folder.Fullname
  38. $sheet.Cells.Item($intRow, 2) = $ACL.IdentityReference.ToString() | ForEach-Object {$_.split('')[1]}
  39. $sheet.Cells.Item($intRow, 3) = $ACL.AccessControlType.ToString()
  40. #Determine the level of access based on security descriptor and put that into the Rights variable
  41. If ($ACL.FileSystemRights -eq 2032127) {$Rights = "Full Control"}
  42. ElseIf ($ACL.FileSystemRights -eq 1048608) {$Rights = "Traverse"}
  43. ElseIf ($ACL.FileSystemRights -eq 1179785) {$Rights = "List Folder, Read Attributes, Read Extended"}
  44. ElseIf ($ACL.FileSystemRights -eq 1048852) {$Rights = "Create Folders, Write Attributes, Write Extended"}
  45. ElseIf ($ACL.FileSystemRights -eq 1048854) {$Rights = "Create Files, Create Folders, Write Attributes, Write Extended"}
  46. ElseIf ($ACL.FileSystemRights -eq 1048609) {$Rights = "Traverse, List Folder"}
  47. ElseIf ($ACL.FileSystemRights -eq 1245631) {$Rights = "Traverse, List Folder, Read Attributes, Read Extended, Create Files, Create Folders, Write Attributes, Write Extended, Delete, Read Permissions"}
  48. ElseIf ($ACL.FileSystemRights -eq 1048577) {$Rights = "List Folder, Read Data"}
  49. ElseIf ($ACL.FileSystemRights -eq 851968) {$Rights = "Delete, Change Permissions, Take Ownership"}
  50. ElseIf ($ACL.FileSystemRights -eq 1180159) {$Rights = "Traverse, List Folder, Read Attributes, Read Extended, Create Files, Create Folders, Write, Write Extended, Delete Subfolders and Files, Read Permissions"}
  51. ElseIf ($ACL.FileSystemRights -eq 524288) {$Rights = "Take Ownership"}
  52. ElseIf ($ACL.FileSystemRights -eq 1507839) {$Rights = "All Permissions (except Take Ownership)"}
  53. ElseIf ($ACL.FileSystemRights -eq 786432) {$Rights = "Change Permissions, Take Ownership"}
  54. ElseIf ($ACL.FileSystemRights -eq 1245695) {$Rights = "All Permissions (except take ownership, change permissions)"}
  55. ElseIf ($ACL.FileSystemRights -eq 1245627) {$Rights = "All Permissions (Except Create Folders, Delete Subfolders and Files, Change Permissions, and Take Ownership)"}
  56. ElseIf ($ACL.FileSystemRights -eq 1179817) {$Rights = "Read & Execute"}
  57. #If no match, put the security descriptor into the Rights variable
  58. Else {$Rights = $ACL.FileSystemRights}
  59. #Insert rights data into spreadsheet
  60. $sheet.Cells.Item($intRow, 4) = $Rights
  61. #Add 1 to the IntRow variable to continue inserting data, but on the next line down
  62. $intRow = $intRow + 1
  63. }
  64. $i = $i + 1
  65. $excel.sheets.add()
  66. }
  67. $WorkBook.EntireColumn.AutoFit()
  68. #$Sheet.Cells.Item($intRow,1).Font.Bold = $True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement