简体   繁体   English

使用 PnP 获取 SharePoint Online 的用户角色和权限

[英]Fetch user roles and permissions for SharePoint Online using PnP

I'm looking to fetch the SharePoint group roles and permissions using SharePoint-PnP for the Site Collection.我希望使用 SharePoint-PnP 为网站集获取 SharePoint 组角色和权限。

I was able to retrieve the SharePoint Groups using $Web.SiteGroups but failed to find the properties for fetching Roles and Permissions.我能够使用$Web.SiteGroups检索 SharePoint 组,但未能找到用于获取角色和权限的属性。

Using the following code snippet to retrieve Group ID, Title and Description.使用以下代码片段检索组 ID、标题和描述。

#Import the required DLL
Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll'
Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'
#OR
#Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll'
#Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'

#Mysite URL
$site = 'https://test.test.com/sites/sitename'

#Admin User Principal Name
$admin = 'LoginID'

#Get Password as secure String
#$password = Read-Host 'Enter Password' -AsSecureString
$password = Read-Host -Prompt "Enter password" -AsSecureString 


#Get the Client Context and Bind the Site Collection
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site)

#Authenticate
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($admin , $password)
$context.Credentials = $credentials

$list = $context.Web.Lists.GetByTitle('ListName')

$web = $context.Web
$context.Load($web)
$context.Load($web.SiteGroups)
$context.Load($list)
$context.ExecuteQuery()

foreach($x in $web.SiteGroups)
{
    Write-Host $x.Id
    Write-Host $x.Title
    Write-Host $x.Description
}
$list.Update()

I don't have the option to go with the SharePoint Online DLL as I don't have the access to run the script as tenant administrator, but site collection administrator.我无法选择使用 SharePoint Online DLL,因为我无权以租户管理员身份运行脚本,但以网站集管理员身份运行。

It would be helpful if this at all can be achieved using PnP ?如果这完全可以使用 PnP 来实现,那会很有帮助吗? Any other solutions are welcome.欢迎任何其他解决方案。

Try this pnp script to get group role and permission in the site:试试这个 pnp 脚本来获取站点中的组角色和权限:

$cred = get-credential
Connect-PnPOnline -Url "https://tenant.sharepoint.com/sites/dev" -Credentials $cred
$web = Get-PnPWeb -Includes RoleAssignments
foreach($ra in $web.RoleAssignments) {
    $member = $ra.Member
    $loginName = get-pnpproperty -ClientObject $member -Property LoginName
    $rolebindings = get-pnpproperty -ClientObject $ra -Property RoleDefinitionBindings
    write-host "$($loginName) - $($rolebindings.Name)"
    write-host  
}

在此处输入图片说明

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

相关问题 Sharepoint 使用 powershell pnp 对文件夹的权限 - Sharepoint permissions to folders using powershell pnp 使用 pnp 更新 SharePoint 在线文档库列属性 PowerShell - update SharePoint online document library column property using pnp PowerShell 使用 PoweShell PnP 更新 SharePoint Online 列表中的查找列 - Updating a lookup column in SharePoint Online list using PoweShell PnP 使用PnP PowerShell for SharePoint Online在文档库上设置“说明” - Setting the “Description” on a Document Library using PnP PowerShell for SharePoint Online 需要使用 PnP 在线 SharePoint 中添加语言翻译器 PowerShell - Need to Add Translators for Language in SharePoint Online using PnP PowerShell PnP 脚本获取 SharePoint 在线文档库的根文件夹并设置唯一权限 - PnP Script to get root folders of a SharePoint online document library and set unique permissions 在 SharePoint Online 中创建文件夹时遇到问题(PnP 模块) - Trouble creating folder in SharePoint Online (PnP module) Powershell PnP - 在线登录 Sharepoint 并下载文件 - Powershell PnP - login to Sharepoint online and download file 如何正确获取列表权限 SharePoint PnP - How to properly get list permissions SharePoint PnP 使用 Powershell(选项 1 - 使用 PnP.Powershell)将文件上传到 Sharepoint Online (Microsoft 365) - Upload file to Sharepoint Online (Microsoft 365) using Powershell (Option 1-Using PnP.Powershell)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM