PowerShell CSOM get SharePoint List members permissions

Clear-Host


Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" 
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" 

$siteUrl = "http://sp" 

$user = "contoso\administrator"

$password = "Access1" | ConvertTo-SecureString -AsPlainText -Force

$ctx = new-object Microsoft.SharePoint.Client.ClientContext($siteUrl)

$credentials = $ctx.Credentials = New-Object System.Net.NetworkCredential($user, $password)
$ctx.Credentials = $credentials

$web = $ctx.Web
$list = $web.Lists.GetByTitle("Student") 
$ctx.Load($list)

$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
}
}

Comments

Popular posts from this blog

Clearing the Configuration Cache for SharePoint

SharePoint 2013 REST API CRUD Operations

Add List Item Attachments to Task Form using Nintex Workflow and Forms