Share via


Microsoft Entra Id'de PowerShell kullanarak kaynak kapsamıyla özel roller atama

Bu makalede, Microsoft Entra Id'de kuruluş genelinde bir rol ataması oluşturma açıklanmaktadır. Kuruluş geneli kapsamında rol atamak, Microsoft Entra kuruluşu genelinde erişim sağlar. Tek bir Microsoft Entra kaynağının kapsamına sahip bir rol ataması oluşturmak için bkz . Microsoft Entra Id'de özel rol oluşturma ve atama. Bu makalede Microsoft Graph PowerShell SDK modülü kullanılmaktadır.

Microsoft Entra rolleri hakkında daha fazla bilgi için bkz . Microsoft Entra yerleşik rolleri.

Önkoşullar

  • Microsoft Entra Kimlik P1 veya P2 lisansı
  • Ayrıcalıklı Rol Yöneticisi
  • PowerShell kullanırken Microsoft Graph PowerShell modülü

Daha fazla bilgi için bkz . PowerShell veya Graph Explorer'ı kullanma önkoşulları.

Kaynak kapsamına sahip bir kullanıcıya veya hizmet sorumlusuna dizin rolü atama

  1. Microsoft Graph PowerShell modülünü yükleyin.

  2. komutunu Connect-MgGraphyürüterek oturum açın.

  3. Aşağıdaki PowerShell betiğini kullanarak yeni bir rol oluşturun.

    ## Assign a role to a user or service principal with resource scope
    # Get the user and role definition you want to link
    $user = Get-MgUser -Filter "UserPrincipalName eq 'cburl@f128.info'"
    $roleDefinition = Get-MgRoleManagementDirectoryRoleDefinition -Filter "DisplayName eq 'Application Support Administrator'"
    
    # Get app registration and construct resource scope for assignment.
    $appRegistration = Get-MgApplication -Filter "displayName eq 'f/128 Filter Photos'"
    $directoryScope = '/' + $appRegistration.Id
    
    # Create a scoped role assignment
    $roleAssignment = New-MgRoleManagementDirectoryRoleAssignment -DirectoryScopeId $directoryScope `
       -RoleDefinitionId $roleDefinition.Id -PrincipalId $user.Id
    

Rolü kullanıcı yerine hizmet sorumlusuna atamak için Get-MgServicePrincipal cmdlet'ini kullanın.

Rol tanımları

Rol tanımı nesneleri, yerleşik veya özel rolün tanımını ve bu rol ataması tarafından verilen izinleri içerir. Bu kaynak hem özel rol tanımlarını hem de yerleşik dizin rollerini (roleDefinition eşdeğeri biçiminde görüntülenir) görüntüler. Bir Microsoft Entra kuruluşunda oluşturulabilecek en fazla özel rol sayısı hakkında bilgi için bkz . Microsoft Entra hizmet sınırları ve kısıtlamaları.

Rol tanımı oluşturma

# Basic information
$description = "Can manage credentials of application registrations"
$displayName = "Application Registration Credential Administrator"
$templateId = (New-Guid).Guid

# Set of actions to include
$rolePermissions = @{
    "allowedResourceActions" = @(
        "microsoft.directory/applications/standard/read",
        "microsoft.directory/applications/credentials/update"
    )
}

# Create new custom directory role
$customAdmin = New-MgRoleManagementDirectoryRoleDefinition -RolePermissions $rolePermissions `
   -DisplayName $displayName -Description $description -TemplateId $templateId -IsEnabled:$true

Rol tanımlarını okuma ve listeleme

# Get all role definitions
Get-MgRoleManagementDirectoryRoleDefinition

# Get single role definition by ID
Get-MgRoleManagementDirectoryRoleDefinition -UnifiedRoleDefinitionId 86593cfc-114b-4a15-9954-97c3494ef49b

# Get single role definition by templateId
Get-MgRoleManagementDirectoryRoleDefinition -Filter "TemplateId eq 'c4e39bd9-1100-46d3-8c65-fb160da0071f'"

Rol tanımını güncelleştirme

# Update role definition
# This works for any writable property on role definition. You can replace display name with other
# valid properties.
Update-MgRoleManagementDirectoryRoleDefinition -UnifiedRoleDefinitionId c4e39bd9-1100-46d3-8c65-fb160da0071f `
   -DisplayName "Updated DisplayName"

Rol tanımını silme

# Delete role definition
Remove-MgRoleManagementDirectoryRoleDefinition -UnifiedRoleDefinitionId c4e39bd9-1100-46d3-8c65-fb160da0071f

Rol atamaları

Rol atamaları, belirli bir güvenlik sorumlusunu (kullanıcı veya uygulama hizmet sorumlusu) rol tanımına bağlayan bilgiler içerir. Gerekirse, atanan izinler için tek bir Microsoft Entra kaynağının kapsamını ekleyebilirsiniz. Rol atamasının kapsamını kısıtlamak, yerleşik ve özel roller için desteklenir.

Rol ataması oluşturma

# Get the user and role definition you want to link
$user = Get-MgUser -Filter "userPrincipalName eq 'cburl@f128.info'"
$roleDefinition = Get-MgRoleManagementDirectoryRoleDefinition -Filter "DisplayName eq 'Application Support Administrator'"

# Get app registration and construct resource scope for assignment.
$appRegistration = Get-MgApplication -Filter "displayName eq 'f/128 Filter Photos'"
$directoryScope = '/' + $appRegistration.Id

# Create a scoped role assignment
$roleAssignment = New-MgRoleManagementDirectoryRoleAssignment -DirectoryScopeId $directoryScope `
   -RoleDefinitionId $roleDefinition.Id -PrincipalId $user.Id

Rol atamalarını okuma ve listeleme

# Get role assignments for a given principal
Get-MgRoleManagementDirectoryRoleAssignment -Filter "PrincipalId eq '27c8ca78-ab1c-40ae-bd1b-eaeebd6f68ac'"

# Get role assignments for a given role definition 
Get-MgRoleManagementDirectoryRoleAssignment -Filter "RoleDefinitionId eq '355aed8a-864b-4e2b-b225-ea95482e7570'"

Rol atamasını kaldırma

# Remove role assignment
Remove-MgRoleManagementDirectoryRoleAssignment -UnifiedRoleAssignmentId 'qiho4WOb9UKKgng_LbPV7tvKaKRCD61PkJeKMh7Y458-1'

Sonraki adımlar