Add User to group in AAD through Runbook

Arif Usman 431 Reputation points
2019-12-18T18:31:24.813+00:00

Folks,
I have ask this question in other forum. Goal is to add user to AAD group (distribution group). Trying to run runbook (very new to this), but getting error message (as shown). here is my script.

I have created automation AzureRunAsConnection account.
I have imported AzureAD new Module.

alt text

The error I am getting

alt text

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,367 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Arif Usman 431 Reputation points
    2019-12-18T23:31:44.2+00:00

    So I have changed code little bit and I think it is able to connect but getting bad http request where it is getting
    "$GroupObject = Get-AzureADGroup -All $true | where-object {$_.displayname -eq $EmailGroup} | select objectid"

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Failed
    Error occurred while executing AddGroupMember
    Code: Request_BadRequest
    Message: Invalid object identifier '@{ObjectId=b4fdeec5-xxxx-xxxxx-xxx-xxxxxxx}'.
    RequestId: 6bd5f2bd-f329-4541-b402-02f862463616
    DateTimeStamp: Wed, 18 Dec 2019 23:12:49 GMT
    HttpStatusCode: BadRequest
    HttpStatusDescription: Bad Request
    HttpResponseStatus: Completed
    (Error occurred while executing AddGroupMember
    Code: Request_BadRequest
    Message: Invalid object identifier '@{ObjectId=b4fdeec5-xxxx-xxxxx-xxx-xxxxxxx}'.
    RequestId: 6bd5f2bd-f329-4541-b402-02f862463616
    DateTimeStamp: Wed, 18 Dec 2019 23:12:49 GMT
    HttpStatusCode: BadRequest
    HttpStatusDescription: Bad Request
    HttpResponseStatus: Completed
    )
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


    OUTPUT:
    Logging in to Azure...

    Account : e1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    Environment : AzureCloud

    Tenant : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    TenantId : 5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    TenantDomain : brighthealthplan.com

    eMAIL GROUP @{ObjectId=b4fdeec5-xxxxxxxxxxxxxxxxxxxxxx}

    USER @{ObjectId=a870c179-xxxxxxxxxxxxxxxxxxxxxx}


    alt text


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.