Advertisement
private775

SharePoint library check permission levels

Apr 1st, 2015
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function checkFolderPremissions($fld){
  2.     if($fld.Item -ne $null -and $fld.Item.HasUniqueRoleAssignments ){
  3.         Write-Host "D:$($fld.ServerRelativeUrl)"
  4.         showRights($fld)
  5.     }
  6.     if($fld.Files.Count -gt 0){
  7.         foreach($f in $fld.Files){
  8.             checkFilePremissions $f
  9.         }
  10.     }
  11.     if($fld.SubFolders.Count -gt 0){
  12.         foreach($d in $fld.SubFolders){
  13.             checkFolderPremissions $d
  14.         }
  15.     }
  16. }
  17.  
  18. function checkFilePremissions($fil){
  19.     if($fil.Item -ne $null -and $fil.Item.HasUniqueRoleAssignments ){
  20.         Write-Host "F:$($fil.ServerRelativeUrl)"
  21.     }
  22. }
  23.  
  24. function showRights($fld){
  25.     $dict = New-Object 'system.collections.generic.dictionary[[string],[system.collections.generic.list[string]]]'
  26.     foreach($ra in $fld.Item.RoleAssignments){
  27.         foreach($rdb in $ra.RoleDefinitionBindings){
  28.             if(-not $dict.ContainsKey($rdb.Name)){
  29.                 $ll = new-object 'system.collections.generic.list[string]'
  30.                 $dict.Add($rdb.Name, $ll)
  31.             }
  32.             $ll = $dict[$rdb.Name]
  33.             if(-not $ll.Contains($ra.Member.Name)){
  34.                 $ll.Add($ra.Member.Name)
  35.             }
  36.         }
  37.     }
  38.     $dict
  39. }
  40.  
  41. $w = Get-SPWeb http://xxxxxx.com/sites/Policies
  42. $lists = @( "KEMH", "MWI")
  43.  
  44. foreach($list in $lists){
  45.     $l = $w.Lists.TryGetList($list)
  46.  
  47.     if($l -eq $null){
  48.         throw "List not found: $($list)"
  49.     }
  50.  
  51.  
  52.     $rf = $l.RootFolder
  53.     checkFolderPremissions $rf
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement