Last active
August 29, 2015 14:27
-
-
Save star-crossed/0062ec1e5ef622a4c8e8 to your computer and use it in GitHub Desktop.
SharePoint: Test if a list has unique role assignments (PowerShell)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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