Skip to content

Instantly share code, notes, and snippets.

@aflyen
Last active October 28, 2015 08:57
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 aflyen/4a098b69b9faa43fd1a3 to your computer and use it in GitHub Desktop.
Save aflyen/4a098b69b9faa43fd1a3 to your computer and use it in GitHub Desktop.
function Get-CustomLoadParameter {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[Microsoft.SharePoint.Client.ClientObject]$Object,
[Parameter(Mandatory=$true)]
[string]$PropertyName
)
# Reference: http://sharepoint.stackexchange.com/questions/126221/spo-retrieve-hasuniqueroleassignements-property-using-powershell
$Context = $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)
return $ExpressionArray
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment