0

how do i add a computer device to an existing AAD security group? I create a token with this

$Body = @{
    'tenant'        = $TenantId
    'client_id'     = $ClientId
    'scope'         = 'https://graph.microsoft.com/.default'
    'client_secret' = $ClientSecret
    'grant_type'    = 'client_credentials'
}

$Params = @{
    'Uri'         = "https://login.microsoftonline.com/$TenantId/oauth2/v2.0/token"
    'Method'      = 'Post'
    'Body'        = $Body
    'ContentType' = 'application/x-www-form-urlencoded'
}

$AuthResponse = Invoke-RestMethod @Params

$Headers = @{
    'Authorization' = "Bearer $($AuthResponse.access_token)"
}

After that i can make queries to the Graph API. Fetching group information

Invoke-RestMethod -Uri 'https://graph.microsoft.com/v1.0/groups/<GUID_group>' -Headers $Headers

Getting the correct result with all information of the group.

The microsoft documentatios says to add a member use this:

https://graph.microsoft.com/v1.0/groups/{id}/members/$ref

But where i do define the ObjectID of the computer device? If i run the request like above, nothing will happen, like described in the microsoft docs.

This one also would not work:

https://graph.microsoft.com/v1.0/groups/<GUID_group>/members/<GUID_computer>

Then it says that the group does not exists

"error": {
 "code": "Request_ResourceNotFound",
 "message": "Resource '<GUID_group>' does not exist or one of its queried reference-property objects are not present.",
 "innerError": {
   "date": "2020-08-25T12:47:10",
   "request-id": "bc728016..."
 }
}

Neither GET nor POST works.

Any ideas or is more information needed?

Maybe i am using the wrong query to accomplish what i want to do. I took a look at the directoryObject querys, but everytime i got refered to the Add member to group Site

Thanks!

3
  • "You can add users, organizational contacts, service principals or other groups." From the linked documentation. Commented Aug 25, 2020 at 13:29
  • It also says directoyObject, an i think a device/computer is a directoryObject. Maybe its the wrong query. Thats because i'm asking. Thanks for the reply :-) Commented Aug 25, 2020 at 13:35
  • Please provide correlation id and timestamp of error message Commented Aug 25, 2020 at 14:49

1 Answer 1

0

Please try the below query in the graph explorer

You can get group id by running below query

Get https://graph.microsoft.com/v1.0/groups

To get device id by running below query

Get https://graph.microsoft.com/v1.0/devices

To add the device into the group use groupid and deviceid for below query and you get 204 response

Post https://graph.microsoft.com/v1.0/groups/{groupid}/members/$ref
{
    "@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/deviceid"
}

By using below query you will get the details of group where your device memberof

 GET https://graph.microsoft.com/v1.0/devices/deviceid/memberOf

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.