Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Prompt for file path to file share
- $SharePath = "\servershare" # read-host "prompt"
- #Get a list of first-level sub-folders within the fileshare and put it into the Folders variable
- $Folders = GCI $SharePath* | where {$_.psiscontainer -eq $true}
- $i = 1
- #Declare the Excel variables
- $excel = new-object -comobject excel.application
- $excel.visible = $true
- $excel = $excel.workbooks.add()
- $sheet = $excel.sheets.item(1)
- $introw = 2
- #$workbook = $sheet.usedrange
- #Prompt for file path to export report(s)
- #$exportpath = "\servershare" # read-host "prompt"
- #For each folder on that list, do the following...
- foreach ($Folder in $Folders){
- #Get full ACL list and put it into the ACLs variable
- $ACLs = get-acl $Folder.fullname | ForEach-Object {$_.Access}
- #Name the worksheet the name of the folder
- $CurrentSheet = $excel.sheets.item('sheet' + $i)
- $CurrentSheet.Activate
- $CurrentSheet.name = $Folder.pschildname
- #$sheet.Name = $Folder.pschildname
- #For each ACL on that list, do the following...
- Foreach ($ACL in $ACLs){
- #Set headers in excel file
- $sheet.Cells.Item(1,1).FormulaLocal = "Folder Path"
- $sheet.Cells.Item(1,2).FormulaLocal = "Group/User"
- $sheet.Cells.Item(1,3).FormulaLocal = "Allow/Deny"
- $sheet.Cells.Item(1,4).FormulaLocal = "Level of Permissions"
- #Insert Data
- $sheet.Cells.Item($intRow, 1) = $Folder.Fullname
- $sheet.Cells.Item($intRow, 2) = $ACL.IdentityReference.ToString() | ForEach-Object {$_.split('')[1]}
- $sheet.Cells.Item($intRow, 3) = $ACL.AccessControlType.ToString()
- #Determine the level of access based on security descriptor and put that into the Rights variable
- If ($ACL.FileSystemRights -eq 2032127) {$Rights = "Full Control"}
- ElseIf ($ACL.FileSystemRights -eq 1048608) {$Rights = "Traverse"}
- ElseIf ($ACL.FileSystemRights -eq 1179785) {$Rights = "List Folder, Read Attributes, Read Extended"}
- ElseIf ($ACL.FileSystemRights -eq 1048852) {$Rights = "Create Folders, Write Attributes, Write Extended"}
- ElseIf ($ACL.FileSystemRights -eq 1048854) {$Rights = "Create Files, Create Folders, Write Attributes, Write Extended"}
- ElseIf ($ACL.FileSystemRights -eq 1048609) {$Rights = "Traverse, List Folder"}
- ElseIf ($ACL.FileSystemRights -eq 1245631) {$Rights = "Traverse, List Folder, Read Attributes, Read Extended, Create Files, Create Folders, Write Attributes, Write Extended, Delete, Read Permissions"}
- ElseIf ($ACL.FileSystemRights -eq 1048577) {$Rights = "List Folder, Read Data"}
- ElseIf ($ACL.FileSystemRights -eq 851968) {$Rights = "Delete, Change Permissions, Take Ownership"}
- 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"}
- ElseIf ($ACL.FileSystemRights -eq 524288) {$Rights = "Take Ownership"}
- ElseIf ($ACL.FileSystemRights -eq 1507839) {$Rights = "All Permissions (except Take Ownership)"}
- ElseIf ($ACL.FileSystemRights -eq 786432) {$Rights = "Change Permissions, Take Ownership"}
- ElseIf ($ACL.FileSystemRights -eq 1245695) {$Rights = "All Permissions (except take ownership, change permissions)"}
- ElseIf ($ACL.FileSystemRights -eq 1245627) {$Rights = "All Permissions (Except Create Folders, Delete Subfolders and Files, Change Permissions, and Take Ownership)"}
- ElseIf ($ACL.FileSystemRights -eq 1179817) {$Rights = "Read & Execute"}
- #If no match, put the security descriptor into the Rights variable
- Else {$Rights = $ACL.FileSystemRights}
- #Insert rights data into spreadsheet
- $sheet.Cells.Item($intRow, 4) = $Rights
- #Add 1 to the IntRow variable to continue inserting data, but on the next line down
- $intRow = $intRow + 1
- }
- $i = $i + 1
- $excel.sheets.add()
- }
- $WorkBook.EntireColumn.AutoFit()
- #$Sheet.Cells.Item($intRow,1).Font.Bold = $True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement