繁体   English   中英

SharePoint Online CSOM / PowerShell权限

[英]SharePoint Online CSOM/PowerShell Permissions

我在使用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

退还我错误

集合尚未初始化。 尚未请求或尚未执行请求。 可能需要明确要求。

例外

集合尚未初始化。 尚未请求或尚未执行请求。 可能需要明确要求。

通常,这意味着您正尝试使用的属性(例如,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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM