Powershell 使用PnP获取SharePoint Online的用户角色和权限
我希望使用SharePoint PnP获取网站集的SharePoint组角色和权限 我能够使用Powershell 使用PnP获取SharePoint Online的用户角色和权限,powershell,sharepoint,sharepoint-online,Powershell,Sharepoint,Sharepoint Online,我希望使用SharePoint PnP获取网站集的SharePoint组角色和权限 我能够使用$Web.SiteGroups检索SharePoint组,但未能找到获取角色和权限的属性 使用以下代码段检索组ID、标题和说明 #Import the required DLL Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.
$Web.SiteGroups
检索SharePoint组,但未能找到获取角色和权限的属性
使用以下代码段检索组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()
我没有使用SharePoint Online DLL的选项,因为我没有以租户管理员身份运行脚本的权限,而是以网站集管理员的身份运行脚本
这将是有益的,如果这一切都可以实现使用PnP?欢迎使用任何其他解决方案。尝试此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
}
这个答案对我很有用。谁也不知道这能这么容易做到。谢谢你为我节省了更多的时间。嘿@Jerry_MSFT,我想问一个简单的问题,我怎样才能检索到群组描述呢?因为我在角色分配中找不到任何可以满足我要求的财产。