1

I am looking for some code to find all users or Ad Group who have some sort of permission in specific folder (with broken Permission) in a specific library of a team-site. With the following code I can find all the folder within a library that has unique permission (Broken Inheritance)

$web = Get-SPWeb $SiteURL #$($SiteIdentity.Url)
Write-Host "Site: " $web.Title
#$list = $web.Lists["Shared Documents"] 
$list = $web.GetList($web.Url +"/Documents/")
write-host "Library Title: "$list.Title
$list.Folders  | ft Name, HasUniqueRoleAssignments, Folder

But not getting the list of users/AD group those have some sort of(read , contrib etc) permission on that specific folder.

0

Here is a function that will get a list of the users on folders in a specific library.

function getUsersAndPerm($web){
  $UsersOnFolders = New-Object System.Collections.ArrayList
  foreach($List in $web.Lists){
     if($List.Title -eq "YOUR LIST TITLE"){
        foreach($folder in $List.Folders){

           foreach($user in $folder.RoleAssignments){

               $UserName = $user.Member.LoginName

               foreach($role in $user.RoleDefinitionBindings){
                   if( $role.Name -eq "Administrators" ){
                       $UsersOnFolders.Add("$UserName,Administrators")
                       break                          
                   }
                   elseif( $role.Name -eq "Contributors" ){
                        $UsersOnFolders.Add("$UserName,Contributors")                          
                   }
                   elseif( $role.Name -eq "Read"){
                       $UsersOnFolders.Add("$UserName,Read")                           
                   }
               }
          }
      }
  }
  return $UsersOnFolders
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.