Hi All,
I am working a PowerShell report that generates all user’s permissions as follows:
- All user permissions with inherited and direct permissions (direct permissions) to thesite.
- All user permissions in all document libraries with inherited.
- If the document libraries have direct permissions (break inheritance) to specificfolder and generate folder permissions to those users for that document library within the site.
I have checked Salaudeen’s blog but the scripts specific user and I am not very proficient with PowerShell when it comes to permission levels. I have tried to make some changes so that I can meet my requirements. I am using SharePoint 2013 Windows SharePoint ISE and loaded the Add-PSSnapin "Microsoft.SharePoint.PowerShell"
- I am getting SPSite, SPWeb andSPList objects in PowerShell ISE as shown:
- But not able to get the SubFolder objects within document library. Am I doing something wrong here?
- However, I am still able to get unique folders using the above following code, but I amnot able to get folder permissions such as Full Control, Editto specific users.
Any help in the Folder Permissions within document library PowerShell snippet would be highly be appreciated.
Attached is my PowerShell script.
#Load powershell snapin Add-PSSnapin "Microsoft.SharePoint.PowerShell" Function GetAllDoumentLibraiesPerms($WebAppURL) { #Get All Site Collections of the WebApp $SiteCollections = Get-SPSite -WebApplication $WebAppURL -Limit All #Loop through all site collections foreach($site in $SiteCollections) { Write-Host("`t Site Collection Name: $($site.Url)") #Loop throuh all Sub Sites foreach($w in $Site.AllWebs) { Write-Host “————————Webs—————————–” Write-Host "Web Site names: $($w.Title)" #If the web has Unique permissions if($w.HasUniqueRoleAssignments -eq $True) { #Get all the users granted permissions to the list foreach($WebRoleAssignment in $w.RoleAssignments) { #if a user account if($WebRoleAssignment.Member.userlogin) { Write-Host("------User's Permissions-----") #Get the Permissions assigned to user $WebUserPermissions=@() foreach ($RoleDefinition in $WebRoleAssignment.RoleDefinitionBindings) { $WebUserPermissions += $RoleDefinition.Name +";" } Write-Host ("$($w.Url) `t $($w.Title) `t Direct Permission $($WebUserPermissions) `t $($WebRoleAssignment.Member.LoginName) ") } else #Its is SharePoint Group { foreach($user in $WebRoleAssignment.member.users) { #Get the Group's Permissions on site Write-Host("------Group Permissions-----") $WebGroupPermissions=@() foreach ($RoleDefinition in $WebRoleAssignment.RoleDefinitionBindings) { $WebGroupPermissions += $RoleDefinition.Name +";" } #Send the Data to Log file Write-Host "$($w.Url) `t Site `t $($w.Title) `t Member of $($WebRoleAssignment.Member.Name) Group `t $($WebGroupPermissions) `t $($user.LoginName) " } } } } #Get Permissions of the user on Web $WebPermissions = Get-PermissionInfo $w #loopthrouh the lists and libraries in the site foreach($l in $w.Lists) { #Filter Doc Libs, Eliminate Hidden and only "Douments" library if( ( $l.BaseType -eq "DocumentLibrary”) -and ($l.Hidden -eq $false) -and ($l.Title -eq "Documents") ) { Write-Host "List title is: $($l.Title)" Write-Host "Root Folder : $($l.RootFolder)" #Check Folders with Unique Permissions $UniqueFolders = $l.Folders | where { $_.HasUniqueRoleAssignments -eq $True } #Get Folder permissions foreach($folder in $UniqueFolders) { Write-Host "Unique Folders are: $($folder.Name)" #Get all the users granted permissions to the list foreach($listRoleAssignment in $l.RoleAssignments) { if($listRoleAssignment.Member.userlogin) { #Get the Permissions assigned to user Write-Host "`t ROLE ASSIGNMENT: $($listRoleAssignment.Member) " #$ListUserPermissions=@() $listUserPermissions=@() foreach ($RoleDefinition in $listRoleAssignment.RoleDefinitionBindings) { $listUserPermissions += $RoleDefinition.Name +";" } #Send the Data to Log file #Write-Host "PARENT WEB is $($l.ParentWeb.Url) / and LIST FOLDER IS $($l.RootFolder.Url) `t List `t $($l.Title)`t Direct Permission `t $($listUserPermissions) `t $($listRoleAssignment.Member)" } } #Get the Folder's Permssions $folderPermissions=@() } #Loop through all subfolders and call the function recursively foreach ($SubFolder in $l.RootFolder.SubFolders) { if($SubFolder.Name -ne "Forms") { Write-Host "INSIDE LOOP ==> Folder Name : $($SubFolder.Name)" Write-Host "$($SubFolder.)" foreach($listRoleAssignment in $l.RoleAssignments) { #Is it a User Account? if($listRoleAssignment.Member.userlogin) { #Get the Permissions assigned to user Write-Host "`t FOLDER ROLE ASSIGNMENT: $($listRoleAssignment.Member) " #$ListUserPermissions=@() $listUserPermissions=@() foreach ($RoleDefinition in $listRoleAssignment.RoleDefinitionBindings) { $listUserPermissions += $RoleDefinition.Name +";" } #Send the Data to Log file Write-Host "$($l.ParentWeb.Url) / $($l.RootFolder.Url) `t List `t $($l.Title)`t Direct Permission `t $($listUserPermissions) `t $($listRoleAssignment.Member)" } } } } #GetMyFiles($l.RootFolder) #Add-Content -Path $outputPath -Value ” => Library : $($List.RootFolder) and Size (in MB) $($DocLibSize)” if( $($l.HasUniqueRoleAssignments) -eq $false ) { Write-host "List is Inherited: $($l.HasUniqueRoleAssignments) " } else { Write-host "List is Direct Permssions: $($l.HasUniqueRoleAssignments) " } } } } } } GetAllDoumentLibraiesPerms "http://intranet.contoso.com"
Sandy