azure - 在 Exchange Online 上运行 Add-DistributionGroupMember PS cmdlet 时出现权限错误

标签 azure powershell azure-active-directory exchange-server

我目前正在尝试使用 PowerShell 脚本自动在 Azure AD 中创建用户,并添加到 Exchange Online 中的通讯组。我关注了this指南 - 我已经使用证书设置了应用程序注册,这就是我向 Azure AD 和 Exchange Online 进行身份验证的方式 - 无需人工干预。

我在脚本中运行的特定 Exchange cmdlet(对于 EXO 部分)是 Add-DistributionGroupMember -member "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ea9f998f98aa8e85878b8384c4898587" rel="noreferrer noopener nofollow">[email protected]</a>" -identity "dlist" -BypassSecurityGroupManagerCheck ,一旦我运行它,我就会收到以下错误输出:

Active Directory operation failed on XXXXXXXXXXXXXXX.XXXXXXXXXXX.PROD.OUTLOOK.COM. This error is not retriable. Additional information: Insufficient access rights to perform the operation.
Active directory response: 00002098: SecErr: DSID-XXXXXXXX, problem 4003 (INSUFF_ACCESS_RIGHTS), data 0
    + CategoryInfo          : NotSpecified: (:) [Add-DistributionGroupMember], ADOperationException
    + FullyQualifiedErrorId : [Server=XXXXXXXXXXXXX,RequestId=8ac3130a-4bbe-41a0-b062-4768b6f51234,TimeStamp=1/3/2021 2:18:13 PM] [FailureCategory=Cmdlet-ADOperationException] XXXXXXX,Microsoft.Exchange.Management.RecipientTasks.AddDistribu
   tionGroupMember
    + PSComputerName        : outlook.office365.com

其他 cmdlet,例如 Get-Mailbox工作正常,但这个特定的问题不断给我带来问题。我尝试将 Azure 中我能想到的所有 API 权限授予应用程序,包括委派权限和应用程序权限,但我仍然面临错误。这是当前的完整列表,但我没有取得任何成功:

我还尝试用应用程序权限替换一些委派权限,但也无济于事。我尝试为应用程序分配各种角色,如 article 中提到的。每次我都得到这个Insufficient access rights to perform the operation错误。

有人能告诉我为什么吗?我应该在哪里以及如何授予应用程序必要的权限以将用户添加到分发(邮件)列表?

这几天我一直在四处寻找,但没有找到答案。任何帮助将不胜感激。

最佳答案

根据我的测试,添加 Exchange.ManageAsApp 应用程序权限并分配 Exchange 服务管理员 角色就足够了。

创建 AAD 应用并添加 Exchange.ManageAsApp 应用程序权限。

$appName = 'Exo_V2_App'

$api = (Get-AzureADServicePrincipal -Filter "AppID eq '00000002-0000-0ff1-ce00-000000000000'")

$permission = $api.AppRoles | Where-Object { $_.Value -eq 'Exchange.ManageAsApp' }

$apiPermission = [Microsoft.Open.AzureAD.Model.RequiredResourceAccess]@{
    ResourceAppId  = $api.AppId ;
    ResourceAccess = [Microsoft.Open.AzureAD.Model.ResourceAccess]@{
        Id   = $permission.Id ;
        Type = "Role"
    }
}

$myApp = New-AzureADApplication -DisplayName $appName -ReplyUrls 'http://localhost' -RequiredResourceAccess $apiPermission

$mySP = New-AzureADServicePrincipal -AppID $myApp.AppID

$myApp | Format-List DisplayName,ObjectID,AppID

将服务主体分配给 Exchange 服务管理员角色。

$directoryRole = 'Exchange Service Administrator'

$RoleId = (Get-AzureADDirectoryRole | Where-Object {$_.displayname -eq $directoryRole}).ObjectID

Add-AzureADDirectoryRoleMember -ObjectId $RoleId -RefObjectId $mySP.ObjectID -Verbose

您可以尝试创建一个新的干净的 Azure AD 应用程序,而无需添加其他配置来进行测试。

关于azure - 在 Exchange Online 上运行 Add-DistributionGroupMember PS cmdlet 时出现权限错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65551179/

相关文章:

xml - 通过 powershell 将数据附加到现有的 xml 文件中

c# - 如何重新创建 PowerShell $profile 变量?它在自定义主机中为空

java - 使用 Java 中的 Office 365 REST API 构建守护程序或服务应用程序

azure - 使用 OAuth2 从 Azure 数据工厂向 Azure DevOps 发出 REST API 请求

android - Xamarin android 发现重复的托管类型

ide - 允许在调试时进行编辑的 PowerShell IDE

azure - 将 Azure 应用程序代理与应用服务结合使用

python-3.x - 重用从 DeviceCodeCredential 获得的 token

Azure AD B2C - 创建租户时出现未经身份验证的错误

c# - 来自 IronPython 的 Azure 表存储查询