首页 > 解决方案 > 通过 CLI 将成员添加到 Azure Enterprise App

问题描述

我们的 Azure AD 租户中有一个企业应用程序,用于将用户预配到另一个 SaaS 平台。目前它仅使用“仅同步分配的用户和组”选项进行设置,因为我们不希望整个目录被带过来。

我的问题很简单,有没有办法使用 az-cli(目前已安装 2.0.60 版)将用户添加到该企业应用程序?

我检查了:

我希望有一个简单的角色分配命令可以运行,通过 upn/objectId 将用户添加到企业应用程序。

我团队中的每个人都在使用 Mac,如果有更好的支持,我们可以使用 PowerShellCore。

谢谢!

标签: azure-active-directoryazure-cliaz

解决方案


看来你不能通过 Azure CLI 做到这一点,我的解决方法是使用 powershell 来做到这一点。

我团队中的每个人都在使用 Mac,如果有更好的支持,我们可以使用 PowerShellCore。

首先,你需要安装AzureAD.Standard.Preview支持powershell core的powershell模块,你可以理解这个模块相当于AzureADpowershell core中的module,它们的用法是一样的,都是预览版,更多细节见这个链接

然后尝试以下命令New-AzureADUserAppRoleAssignment ,此示例将用户分配给具有默认应用程序角色 ID 的应用程序。

New-AzureADUserAppRoleAssignment -ObjectId "<user objectid>" -PrincipalId "<user objectid>" -ResourceId "<service principal objectid(i.e. Enterprise Application objectid)>" -Id ([Guid]::Empty)

在此处输入图像描述

检查门户:

在此处输入图像描述

如果要将用户分配给应用程序中的特定应用程序角色,请尝试以下命令。

$username = "<You user's UPN>"
$app_name = "<Your App's display name>"
$app_role_name = "<App role display name>"

# Get the user to assign, and the service principal for the app to assign to
$user = Get-AzureADUser -ObjectId "$username"
$sp = Get-AzureADServicePrincipal -Filter "displayName eq '$app_name'"
$appRole = $sp.AppRoles | Where-Object { $_.DisplayName -eq $app_role_name }

#Assign the user to the app role
New-AzureADUserAppRoleAssignment -ObjectId $user.ObjectId -PrincipalId $user.ObjectId -ResourceId $sp.ObjectId -Id $appRole.Id

推荐阅读