# Basic role information
$description = "Can manage user and group assignments for Applications"
$displayName = "Manage user and group assignments"
$templateId = (New-Guid).Guid
# Set of permissions to grant
$allowedResourceAction = @("microsoft.directory/servicePrincipals/appRoleAssignedTo/update")
$rolePermission = @{'allowedResourceActions'= $allowedResourceAction}
$rolePermissions = $rolePermission
# Create new custom admin role
$customRole = New-MgRoleManagementDirectoryRoleDefinition -Description $description `
-DisplayName $displayName -RolePermissions $rolePermissions -TemplateId $templateId -IsEnabled
カスタム ロールを割り当てる
この PowerShell スクリプトを使用して、ロールを割り当てます。
# Get the user and role definition you want to link
$user = Get-MgUser -Filter "userPrincipalName eq 'chandra@example.com'"
$roleDefinition = Get-MgRoleManagementDirectoryRoleDefinition -Filter "displayName eq 'Manage user and group assignments'"
# Get app registration and construct scope for assignment.
$appRegistration = Get-MgApplication -Filter "displayName eq 'My Filter Photos'"
$directoryScope = '/' + $appRegistration.Id
# Create a scoped role assignment
$roleAssignment = New-MgRoleManagementDirectoryRoleAssignment -DirectoryScopeId $directoryScope `
-PrincipalId $user.Id -RoleDefinitionId $roleDefinition.Id
POST https://graph.microsoft.com/v1.0/roleManagement/directory/roleDefinitions
{
"description": "Can manage user and group assignments for Applications.",
"displayName": "Manage user and group assignments",
"isEnabled": true,
"rolePermissions":
[
{
"allowedResourceActions":
[
"microsoft.directory/servicePrincipals/appRoleAssignedTo/update"
]
}
],
"templateId": "<PROVIDE NEW GUID HERE>",
"version": "1"
}
Microsoft Graph API を使用してカスタム ロールを割り当てる
Create unifiedRoleAssignment API を使用して、カスタム ロールを割り当てます。 ロールの割り当てでは、セキュリティ プリンシパル ID (ユーザーでもサービス プリンシパルでも可)、ロール定義 ID、および Microsoft Entra リソース スコープを組み合わせます。 ロールの割り当ての要素について詳しくは、「カスタム ロールの概要」を参照してください
POST https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments
{
"@odata.type": "#microsoft.graph.unifiedRoleAssignment",
"principalId": "<PROVIDE OBJECTID OF USER TO ASSIGN HERE>",
"roleDefinitionId": "<PROVIDE OBJECTID OF ROLE DEFINITION HERE>",
"directoryScopeId": "/"
}