【问题标题】:Check subsite permission sharepoint online CSOM在线查看子站点权限共享点 CSOM
【发布时间】:2016-11-24 18:18:16
【问题描述】:

使用 Powershell,我正在尝试获取我的 SharePoint 在线环境的子网站的权限。

我试图获得许可的网站位于https://tenant.sharepoint.com/production

我想知道哪些用户或组可以访问此站点。

我正在使用 CSOM 和 Powershell 连接到我的在线环境。

【问题讨论】:

  • 我实际上是使用:一个太长的 PS 脚本无法在此处发布......

标签: powershell sharepoint csom


【解决方案1】:

要获取 组列表,您可以考虑以下示例:

# Retrieve web groups
$groups = $context.Web.RoleAssignments.Groups
$context.Load($groups)
$context.ExecuteQuery()

对于特定网站的用户列表,由于RoleAssignmentCollection 类不公开Users 属性,因此并不那么简单。无论如何,以下示例演示了如何检索网站的用户列表

Function Get-WebUsers() {
param(
   [Microsoft.SharePoint.Client.Web]$Web = $(throw "Please provide a Web")
) 
   $ctx = $Object.Context
   $assignments = $context.Web.RoleAssignments
   $context.Load($assignments)
   $context.ExecuteQuery()

   $members = @()
   $assignments.GetEnumerator() | % { 
       $member = $context.Web.RoleAssignments.GetByPrincipalId($_.PrincipalId).Member
       $context.Load($member)
       $members += $member
   }
   $context.ExecuteQuery()

   $users = @()
   $members | % { 
         if($_.PrincipalType  -eq [Microsoft.SharePoint.Client.Utilities.PrincipalType]::User) {
             $users += $_
         } 
   }
   $users
}

例子:

Add-Type –Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" 
Add-Type –Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Function Get-Context([String]$WebUrl,$UserName,$Password) {
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($WebUrl)
    $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
    $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
    return $context
}


Function Get-WebUsers() {
param(
   [Microsoft.SharePoint.Client.Web]$Web = $(throw "Please provide a Web")
) 
   $ctx = $Object.Context
   $assignments = $context.Web.RoleAssignments
   $context.Load($assignments)
   $context.ExecuteQuery()

   $members = @()
   $assignments.GetEnumerator() | % { 
       $member = $context.Web.RoleAssignments.GetByPrincipalId($_.PrincipalId).Member
       $context.Load($member)
       $members += $member
   }
   $context.ExecuteQuery()

   $users = @()
   $members | % { 
         if($_.PrincipalType  -eq [Microsoft.SharePoint.Client.Utilities.PrincipalType]::User) {
             $users += $_
         } 
   }
   $users
}


$Url = "https://contoso.sharepoint.com/news"
$Username = "jdoe@consoto.onmicrosoft.com"
$Password = ""

$context = Get-Context -WebUrl $Url -UserName $Username -Password $Password

# Retrieve web groups
$groups = $context.Web.RoleAssignments.Groups
$context.Load($groups)
$context.ExecuteQuery()

write "Group names:"
$groups.GetEnumerator() | % { 
    $_.Title 
}

# Retrieve web users
$users = Get-WebUsers -Web $context.Web  
write "User names:"
$users | % { 
    $_.Title 
}

$context.Dispose()

要点:WebUsersAndGroups.ps1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    • 1970-01-01
    • 2018-02-15
    • 1970-01-01
    • 2018-09-04
    • 1970-01-01
    • 2011-08-27
    相关资源
    最近更新 更多