Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SharePoint: Test if a list has unique role assignments (PowerShell)
Import-Module Microsoft.Online.SharePoint.Powershell
Function Invoke-LoadMethod() {
param(
[Microsoft.SharePoint.Client.ClientObject]$Object = $(throw "Please provide a Client Object"),
[string]$PropertyName
)
$ctx = $Object.Context
$load = [Microsoft.SharePoint.Client.ClientContext].GetMethod("Load")
$type = $Object.GetType()
$clientLoad = $load.MakeGenericMethod($type)
$Parameter = [System.Linq.Expressions.Expression]::Parameter(($type), $type.Name)
$Expression = [System.Linq.Expressions.Expression]::Lambda(
[System.Linq.Expressions.Expression]::Convert(
[System.Linq.Expressions.Expression]::PropertyOrField($Parameter,$PropertyName),
[System.Object]
),
$($Parameter)
)
$ExpressionArray = [System.Array]::CreateInstance($Expression.GetType(), 1)
$ExpressionArray.SetValue($Expression, 0)
$clientLoad.Invoke($ctx,@($Object,$ExpressionArray))
}
$password = Read-Host -Prompt "Enter password" -AsSecureString
[Microsoft.SharePoint.Client.ClientContext]$context = New-Object Microsoft.SharePoint.Client.ClientContext("https://jjkllc.sharepoint.com/sites/kma/extranet")
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("pchoquette@jjkllc.com", $password)
$list = $context.Web.Lists.GetByTitle("Bids")
Invoke-LoadMethod -Object $list -PropertyName "HasUniqueRoleAssignments"
$context.ExecuteQuery()
Write-Host $list.HasUniqueRoleAssignments
$context.Dispose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment