azure - 如何使用 Powershell 将用户分配的身份添加到 AAD 组?

标签 azure powershell azure-active-directory azure-managed-identity

我可以使用以下命令将服务主体和个人用户添加到 Azure Active Directory 组:

Add-AzADGroupMember -TargetGroupObjectId GROUPID -MemberObjectId MEMBERID

我将从门户为用户分配托管身份主体 ID 作为 MemberObjectId。我想 ID 是别的东西,但它是什么以及如何获得它?我也尝试过客户端 ID,但没有成功。

当我尝试使用用户分配的托管 ID 运行相同的命令时,它失败并出现错误:

行| 143 | 143 Az.MSGraph.internal\New-AzADGroupGraphRefMember @PSBoundP … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~ |资源“XXXXX-...”不存在或其查询的引用属性对象之一 |不存在。



最佳答案

我尝试在我的环境中重现相同的结果,并得到以下结果

我有一个名为 UsersignedMI用户分配的托管身份,如下所示:

enter image description here

为了将上述身份添加到 Azure AD 组,我通过提供客户端 ID 运行了与您相同的命令,并得到了相同的错误,如下所示:

Add-AzADGroupMember -TargetGroupObjectId <GroupID> -MemberObjectId <Client ID>

回应:

enter image description here

但是当我使用对象(主要)ID作为-MemberObjectID时,它起作用并成功给出了结果,如下所示:

Add-AzADGroupMember -TargetGroupObjectId <GroupID> -MemberObjectId <Object (principal) ID>
Get-AzADGroupMember -GroupObjectId <GroupID>

回应:

enter image description here

当我在门户中检查相同内容时,托管身份成功添加到组中,如下所示:

enter image description here

关于azure - 如何使用 Powershell 将用户分配的身份添加到 AAD 组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74626653/

相关文章:

azure - 如何使用 Azure CLI 或 Terraform 创建 DNS A 记录

powershell - 如何通过 Google Calendar API 检索相关日历事件?

powershell - Get-ADUser 按属性长度过滤

asp.net-mvc - 使用 Azure Active Directory OAuth 时没有名字或姓氏声明

asp.net-core - 使用 Azure AD V2.0 (MSAL) 和 Asp .Net Core 2.0 获取刷新 token

Azure B2C 自定义策略授权端点给出 404

azure - ssh:连接到端口 22 上的主机:连接被拒绝

azure - 使用 Azure AD 验证个人 MS 帐户时无法使用特定于租户的终结点

azure - 没有有关 Application Insights 的数据

powershell - 多个重复发生的过程