PowerShell을 사용하여 Microsoft 365 사용자 계정에 관리자 역할 할당

이 문서는 Microsoft 365 Enterprise와 Office 365 Enterprise에 모두 적용됩니다.

Microsoft 365용 PowerShell을 사용하여 사용자 계정에 역할을 쉽게 할당할 수 있습니다.

참고

Microsoft 365 관리 센터 사용하여 사용자 계정에 관리자 역할을 할당하는 방법을 알아봅니다.

추가 리소스 목록은 사용자 및 그룹 관리를 참조하세요.

Microsoft Graph PowerShell을 사용하여 사용자 계정에 역할 할당

참고

Azure Active Directory 모듈은 Microsoft Graph PowerShell SDK로 대체됩니다. Microsoft Graph PowerShell SDK를 사용하여 모든 Microsoft Graph API에 액세스할 수 있습니다. 자세한 내용은 Microsoft Graph PowerShell SDK 시작하기를 참조하세요.

먼저 Microsoft Entra DC 관리자, 클라우드 애플리케이션 관리 또는 전역 관리자 계정을 사용하여 Microsoft 365 테넌트에 연결합니다. 이 문서의 cmdlet에는 RoleManagement.ReadWrite.Directory에 scope 권한 또는 'list subscribedSkus' Graph API 참조 페이지에 나열된 다른 권한 중 하나가 필요합니다. 이 문서의 일부 명령에는 다른 사용 권한 범위가 필요할 수 있으며, 이 경우 관련 섹션에 설명되어 있습니다.

Connect-MgGraph -Scopes "RoleManagement.ReadWrite.Directory"

자세한 내용은 관리자 역할 정보를 참조하세요.

다음으로 역할에 추가할 사용자 계정의 로그인 이름을 식별합니다(예: fredsm@contoso.com). 이를 UPN(사용자 계정 이름)으로도 알려져 있습니다.

다음으로 역할의 이름을 확인합니다. 기본 제공 역할 Microsoft Entra 참조하세요.

참고

이 문서의 노트에 주의하세요. 일부 역할 이름은 Azure Active Directory(Azure AD) PowerShell에 대해 다릅니다. 예를 들어 Microsoft 365 관리 센터 SharePoint 관리자 역할은 Azure AD PowerShell의 SharePoint 서비스 관리자입니다.

다음으로, 사용자 UPN 및 역할 이름을 입력하고 다음 명령을 실행합니다.

$userUPN="<user UPN>"
$roleName="<role name>"
$role = Get-MgDirectoryRole | Where-Object {$_.displayName -eq $roleName}
if ($role -eq $null) {
    $roleTemplate = (Get-MgDirectoryRoleTemplate | Where-Object {$_.displayName -eq $roleName}).id
    New-MgDirectoryRole -DisplayName $roleName -RoleTemplateId $roleTemplate
    $role = Get-MgDirectoryRole | Where-Object {$_.displayName -eq $roleName}
}
$userId = (Get-MgUser -Filter "userPrincipalName eq '$userUPN'").Id
$newRoleMember =@{
    "@odata.id"= "https://graph.microsoft.com/v1.0/users/$userId"
    }
New-MgDirectoryRoleMemberByRef -DirectoryRoleId $role.Id -BodyParameter $newRoleMember

다음은 SharePoint 서비스 관리자 역할을 계정에 할당하는 완료된 명령 집합의 예입니다 belindan@contoso.com .

$userUPN="adelev@contoso.com"
$roleName="Exchange Administrator"
$role = Get-MgDirectoryRole | Where-Object {$_.displayName -eq $roleName}
if ($role -eq $null) {
    $roleTemplate = (Get-MgDirectoryRoleTemplate | Where-Object {$_.displayName -eq $roleName}).id
    New-MgDirectoryRole -DisplayName $roleName -RoleTemplateId $roleTemplate
    $role = Get-MgDirectoryRole | Where-Object {$_.displayName -eq $roleName}
}
$userId = (Get-MgUser -Filter "userPrincipalName eq '$userUPN'").Id
$newRoleMember =@{
    "@odata.id"= "https://graph.microsoft.com/v1.0/users/$userId"
    }
New-MgDirectoryRoleMemberByRef -DirectoryRoleId $role.Id -BodyParameter $newRoleMember

특정 관리자 역할에 대한 사용자 ID 목록을 표시하려면 다음 명령을 사용합니다.

$roleName="<role name>"
Connect-MgGraph -Scopes "Directory.Read.All"
Get-MgDirectoryRole | Where-Object { $_.DisplayName -eq $roleName } | ForEach-Object { Get-MgDirectoryRoleMember -DirectoryRoleId $_.Id }

참고 항목