Guest User

Untitled

a guest
Jan 24th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll"
  2. Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
  3.  
  4. $siteUrl = "https://mysiteURL"
  5.  
  6. $ctx = new-object Microsoft.SharePoint.Client.ClientContext($siteUrl)
  7.  
  8. $web = $ctx.Web
  9. $list = $web.Lists.GetByTitle("GENERAL DOCUMENTS")
  10. #$ctx.Load($list)
  11. $ctx.Load()
  12.  
  13. $ctx.ExecuteQuery()
  14.  
  15. $listroleassignments = $list.RoleAssignments
  16. $ctx.Load($listroleassignments)
  17. $ctx.ExecuteQuery()
  18.  
  19. foreach($listroleassgnment in $listroleassignments)
  20. {
  21. $ctx.Load($listroleassgnment.Member)
  22. $ctx.Load($listroleassgnment.RoleDefinitionBindings)
  23. $ctx.ExecuteQuery()
  24.  
  25. foreach($listroledefinition in $listroleassgnment.RoleDefinitionBindings)
  26. {
  27. $ctx.Load($listroledefinition)
  28. $ctx.ExecuteQuery()
  29. Write-Host -ForegroundColor Green $listroleassgnment.Member.Title: $listroledefinition.Name
  30. }
  31. }
  32.  
  33. Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll"
  34. Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
  35. cls
  36.  
  37. $username = "user@company.onmicrosoft.com"
  38. $password = ConvertTo-SecureString "pwd" -AsPlainText -Force
  39.  
  40. $siteUrl = [string]::Format("https://company.sharepoint.com")
  41. $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
  42. $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
  43.  
  44. function GetPermission($Web,$ctx)
  45. {
  46. # Root Web
  47. $Web = $ctx.Web
  48. $WebRAs = $Web.RoleAssignments
  49. $ctx.Load($Web)
  50. $ctx.Load($WebRAs)
  51. $ctx.ExecuteQuery()
  52.  
  53. Write-Host $Web.Url -ForegroundColor Cyan
  54.  
  55. foreach($WebRA in $WebRAs)
  56. {
  57. $ctx.Load($WebRA.Member)
  58. $ctx.Load($WebRA.RoleDefinitionBindings)
  59. $ctx.ExecuteQuery()
  60.  
  61. foreach($WebDB in $WebRA.RoleDefinitionBindings)
  62. {
  63. $ctx.Load($WebDB)
  64. $ctx.ExecuteQuery()
  65. Write-Host -ForegroundColor Green $WebRA.Member.Title: $WebDB.Name
  66. }
  67. }
  68.  
  69. # Root Lists
  70. $Lists = $Web.Lists
  71. $ctx.Load($Lists)
  72. $ctx.ExecuteQuery()
  73.  
  74. foreach($List in $Lists)
  75. {
  76. $ctx.Load($List)
  77. Write-Host $List.Title -ForegroundColor Yellow
  78. $ListRAs = $List.RoleAssignments
  79. $ctx.ExecuteQuery()
  80. $ctx.Load($ListRAs)
  81. $ctx.ExecuteQuery()
  82.  
  83. foreach($ListRA in $ListRAs)
  84. {
  85. $ctx.Load($ListRA.Member)
  86. $ctx.Load($ListRA.RoleDefinitionBindings)
  87. $ctx.ExecuteQuery()
  88.  
  89. foreach($ListRD in $ListRA.RoleDefinitionBindings)
  90. {
  91. $ctx.Load($ListRD)
  92. $ctx.ExecuteQuery()
  93. Write-Host -ForegroundColor Green $ListRA.Member.Title: $ListRD.Name
  94. }
  95.  
  96. #Here can be added $List.Items in same way
  97. }
  98. }
  99. }
  100.  
  101. GetPermission -Web $siteUrl -ctx $ctx
  102.  
  103. # Sub Webs
  104. $ctx.Load($Web.Webs)
  105. $ctx.ExecuteQuery()
  106.  
  107. foreach($Web in $Webs)
  108. {
  109. GetPermission -Web $Web -ctx $ctx
  110. }
Add Comment
Please, Sign In to add comment