Skip to content

Instantly share code, notes, and snippets.

@star-crossed
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save star-crossed/0062ec1e5ef622a4c8e8 to your computer and use it in GitHub Desktop.
Save star-crossed/0062ec1e5ef622a4c8e8 to your computer and use it in GitHub Desktop.
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