在 Microsoft Graph 上将服务主体分配给 SharePoint 管理员角色时“不支持角色分配”

问题描述 投票:0回答:1

我想将我的应用程序(服务)主体分配给 Microsoft Entra ID 中的 SharePoint 管理员角色,因为我的应用程序在 SharePoint 端写入临时(元)数据,如此处

所示
web.AllProperties["name"] = "value";
web.Update();
ctx.ExecuteQuery();

我正在使用以下 PowerShell 代码片段,它会抛出 不支持角色分配错误,

Install-Module Microsoft.Graph.Authentication, Microsoft.Graph.Applications, Microsoft.Graph.Identity.SignIns, Microsoft.Graph.Identity.Governance -Force

Connect-MgGraph -Scopes @(
 "AppRoleAssignment.ReadWrite.All"
 "Application.ReadWrite.All"
 "Directory.ReadWrite.All")

$appId = "my-app-id-comes-here"

$servicePrincipal = Get-MgServicePrincipal -Filter "appId eq '$appId'"

New-MgRoleManagementDirectoryRoleEligibilityScheduleRequest -Action "SelfActivate" -Justification "For writing metadata to SharePoint tenant settings" -DirectoryScopeId "/" -PrincipalId $servicePrincipal.Id -RoleDefinitionId "f28a1f50-f6e7-4571-818b-6a12f2af6b6c" -ScheduleInfo @{
 "StartDateTime" = [System.DateTime]::Now.AddSeconds(10)
 "Expiration" = @{
 "Type" = "NoExpiration"
 }
}

我还尝试了应用程序(服务)主体的对象ID而不是

$servicePrincipal.Id
,错误消息更改为未找到主题

azure powershell sharepoint permissions microsoft-graph-sdks
1个回答
0
投票
将服务主体分配给 Microsoft Graph 上的 SharePoint 管理员角色时,

“不支持角色分配”

当我尝试将 SharePoint Administrator 角色分配给

Service Principal
时,遇到了与下面相同的错误。

或者,您可以使用下面的 Service Principal 脚本将

SharePoint Administrator
角色分配给
PowerShell

enter image description here

    Connect-MgGraph -Scopes @(
     "AppRoleAssignment.ReadWrite.All""Application.ReadWrite.All""Directory.ReadWrite.All")
    $appId="bf7e17bd-xxxxxxxxxxxxxxxxxx"
    $servicePrincipal = Get-MgServicePrincipal -Filter "appId eq '$appId'"
    
    $roledefinition = Get-MgRoleManagementDirectoryRoleDefinition -Filter "DisplayName eq 'SharePoint Administrator'"
    
    $roleassignment = New-MgRoleManagementDirectoryRoleAssignment -DirectoryScopeId '/' -RoleDefinitionId $roledefinition.Id -PrincipalId $servicePrincipal.Id

输出:

enter image description here

运行脚本后,SharePoint Administrator角色已成功分配给

Service principal

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.