Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
- $siteUrl = "https://mysiteURL"
- $ctx = new-object Microsoft.SharePoint.Client.ClientContext($siteUrl)
- $web = $ctx.Web
- $list = $web.Lists.GetByTitle("GENERAL DOCUMENTS")
- #$ctx.Load($list)
- $ctx.Load()
- $ctx.ExecuteQuery()
- $listroleassignments = $list.RoleAssignments
- $ctx.Load($listroleassignments)
- $ctx.ExecuteQuery()
- foreach($listroleassgnment in $listroleassignments)
- {
- $ctx.Load($listroleassgnment.Member)
- $ctx.Load($listroleassgnment.RoleDefinitionBindings)
- $ctx.ExecuteQuery()
- foreach($listroledefinition in $listroleassgnment.RoleDefinitionBindings)
- {
- $ctx.Load($listroledefinition)
- $ctx.ExecuteQuery()
- Write-Host -ForegroundColor Green $listroleassgnment.Member.Title: $listroledefinition.Name
- }
- }
- Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
- cls
- $username = "user@company.onmicrosoft.com"
- $password = ConvertTo-SecureString "pwd" -AsPlainText -Force
- $siteUrl = [string]::Format("https://company.sharepoint.com")
- $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
- $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
- function GetPermission($Web,$ctx)
- {
- # Root Web
- $Web = $ctx.Web
- $WebRAs = $Web.RoleAssignments
- $ctx.Load($Web)
- $ctx.Load($WebRAs)
- $ctx.ExecuteQuery()
- Write-Host $Web.Url -ForegroundColor Cyan
- foreach($WebRA in $WebRAs)
- {
- $ctx.Load($WebRA.Member)
- $ctx.Load($WebRA.RoleDefinitionBindings)
- $ctx.ExecuteQuery()
- foreach($WebDB in $WebRA.RoleDefinitionBindings)
- {
- $ctx.Load($WebDB)
- $ctx.ExecuteQuery()
- Write-Host -ForegroundColor Green $WebRA.Member.Title: $WebDB.Name
- }
- }
- # Root Lists
- $Lists = $Web.Lists
- $ctx.Load($Lists)
- $ctx.ExecuteQuery()
- foreach($List in $Lists)
- {
- $ctx.Load($List)
- Write-Host $List.Title -ForegroundColor Yellow
- $ListRAs = $List.RoleAssignments
- $ctx.ExecuteQuery()
- $ctx.Load($ListRAs)
- $ctx.ExecuteQuery()
- foreach($ListRA in $ListRAs)
- {
- $ctx.Load($ListRA.Member)
- $ctx.Load($ListRA.RoleDefinitionBindings)
- $ctx.ExecuteQuery()
- foreach($ListRD in $ListRA.RoleDefinitionBindings)
- {
- $ctx.Load($ListRD)
- $ctx.ExecuteQuery()
- Write-Host -ForegroundColor Green $ListRA.Member.Title: $ListRD.Name
- }
- #Here can be added $List.Items in same way
- }
- }
- }
- GetPermission -Web $siteUrl -ctx $ctx
- # Sub Webs
- $ctx.Load($Web.Webs)
- $ctx.ExecuteQuery()
- foreach($Web in $Webs)
- {
- GetPermission -Web $Web -ctx $ctx
- }
Add Comment
Please, Sign In to add comment