如何将AAD组分配给企业应用程序?

发布于 2025-02-10 00:20:40 字数 603 浏览 3 评论 0原文

我想知道如何将一个或多个组分配给应用程序?

我已经尝试过,但是我遇到了一个错误: Get-azureadGroup:执行GetGroup时发生错误

connect-azuread

$GroupName = "TEST"
$app_name = "Intranet"
$app_role_name = "Default Access"

# Get the group to assign
$AADGROUP = Get-AzureADGroup -ObjectId $GroupName
$sp = Get-AzureADServicePrincipal -Filter "displayName eq '$app_name'"
$appRole = $sp.AppRoles | Where-Object { $_.DisplayName -eq $app_role_name }

# Assign the group to the app role
New-AzureADGroupAppRoleAssignment -ObjectId $AADGROUP.ObjectId -PrincipalId $AADGROUP.ObjectId -ResourceId $sp.ObjectId -Id $appRole.Id

i would like to know how to assign one or multiple groups to an application?

I've tried this but im getting an error:
Get-AzureADGroup : Error occurred while executing GetGroup

connect-azuread

$GroupName = "TEST"
$app_name = "Intranet"
$app_role_name = "Default Access"

# Get the group to assign
$AADGROUP = Get-AzureADGroup -ObjectId $GroupName
$sp = Get-AzureADServicePrincipal -Filter "displayName eq '$app_name'"
$appRole = $sp.AppRoles | Where-Object { $_.DisplayName -eq $app_role_name }

# Assign the group to the app role
New-AzureADGroupAppRoleAssignment -ObjectId $AADGROUP.ObjectId -PrincipalId $AADGROUP.ObjectId -ResourceId $sp.ObjectId -Id $appRole.Id

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生不灭 2025-02-17 00:20:40

您的错误清楚地表明了失败的零件。
在上一个语句中没有提供objectid,因为您的$ aadgroup.ObjectID is $ null

查看您的代码摘录:

$GroupName = 'test'
$AADGROUP = Get-AzureADGroup -ObjectId $GroupName
#...
# Assign the group to the app role
New-AzureADGroupAppRoleAssignment -ObjectId $AADGROUP.ObjectId -PrincipalId $AADGROUP.ObjectId -ResourceId $sp.ObjectId -Id $appRole.Id

$ groupName如果您将其与get -azureadGroup -objectID $ groupName语句使用。它行不通。 -ObjectID期望组的对象ID GUID,而不是其名称(您可能已经正确地执行了它,我的假设来自您的变量名称)。

这将解释您没有返回的任何组以及发生错误的原因。
如果要使用组名称,则需要使用get-azureadgroup使用-SearchString而不是-ObjectID

Your error indicate clearly the part which is failing.
There is no ObjectId provided to the last statement because your $AADGroup.ObjectId is $null

Looking at an excerpt of your code:

$GroupName = 'test'
$AADGROUP = Get-AzureADGroup -ObjectId $GroupName
#...
# Assign the group to the app role
New-AzureADGroupAppRoleAssignment -ObjectId $AADGROUP.ObjectId -PrincipalId $AADGROUP.ObjectId -ResourceId $sp.ObjectId -Id $appRole.Id

$GroupName is a very bad name for this variable if you are using it along with the Get-AzureADGroup -ObjectId $GroupName statement right after. It won't work. -ObjectId is expecting the object ID GUID of the group, not its name (You might be already doing it correctly, my assumption come from your variable name).

That would explain where you don't have any group returned and why the error occur.
If you want to use the group name, you will need to call the Get-AzureADGroup with -SearchString instead of -ObjectId.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文