2017-02-21 117 views
0

我有问题使用CSOM/PowerShell列出权限列表。SharePoint Online CSOM/PowerShell权限

变量/过滤器

$spSiteUrl = "https://mytenant.sharepoint.com" 

获取证书

if($cred -eq $null) 
{ 
    $cred = Get-Credential 
} 

装载程序集

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null 
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null 

连接到SharePoint,并显示网站标题

Write-Host "Connecting to SharePoint" 
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($spSiteUrl) 
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($cred.UserName, $cred.Password) 

$web = $ctx.Web 
$ctx.Load($web) 
$ctx.ExecuteQuery() 
Write-host "Site Name : $($web.Title)" 

功能列表 “有用” 的应用

function getApps($web) 
{ 
    $appsArray = @() 

    $apps = $web.Lists 
    $ctx.Load($apps) 

    $ctx.ExecuteQuery() 

    Write-Host "List of aplications : " 
    foreach($app in $apps){ 
     if($app.Hidden -eq $false) 
     { 
      $item = New-Object PSObject 
      $item | Add-Member -MemberType NoteProperty -Name 'Col1' -Value $($app.Title) 
      $item | Add-Member -MemberType NoteProperty -Name 'Col2' -Value $($app.HasUniqueRoleAssignments) 
      $item | Add-Member -MemberType NoteProperty -Name 'Col3' -Value $($app.RoleAssignments) 
      $item | Add-Member -MemberType NoteProperty -Name 'Col4' -Value $($app.BrowserFileHandling) 
      $item | Add-Member -MemberType NoteProperty -Name 'Col5' -Value $($app.EffectiveBasePermissions) 
      $item | Add-Member -MemberType NoteProperty -Name 'Col6' -Value $($app.Fields) 
      $item | Add-Member -MemberType NoteProperty -Name 'Col7' -Value $($app.WorkflowAssociations) 
      $appsArray += $item 
     } 
    } 
    $appsArray | Format-Table 
} 

调用函数

getApps($web) 

我的问题是:

  • $ app.HasUniqueRoleAssignments
  • $ app.RoleAssignments
  • 个$ app.BrowserFileHandling
  • $ app.EffectiveBasePermissions
  • $ app.Fields
  • $ app.WorkflowAssociations

回到我的错误

收集尚未初始化。它没有被请求或者 请求没有被执行。这可能需要明确 要求..

回答

0

例外

收集尚未初始化。它没有被请求或者 请求没有被执行。它可能需要明确要求 。

通常意味着您尝试使用的属性(例如,HasUniqueRoleAssignments)尚未从服务器中检索到。

你可能需要额外的executeQuery加载每个应用程序

foreach($app in $apps){ 
if($app.Hidden -eq $false) 
{ 
$ctx.Load($app) 
$ctx.ExecuteQuery() 

你最终会发现,某些属性无法用常规CSOM API(如HasUniqueRoleAssignments),并为那些可以使用Gary的PowerShell的检索,让您的可能性做什么,否则你会使用LINQ

foreach($app in $apps){ 
if($app.Hidden -eq $false) 
{ 
$ctx.Load($app) 
Load-CSOMProperties -object $app -propertyNames @("HasUniqueRoleAssignments") 
$ctx.ExecuteQuery() 

https://gist.github.com/glapointe/cc75574a1d4a225f401b#file-load-csomproperties-ps1

https://sharepoint.stackexchange.com/questions/126221/spo-retrieve-hasuniqueroleassignements-property-using-powershell