[英]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.