--- title: "Add a User to an M365 Group or Team via Microsoft Graph" slug: "dex-wf-add-user-to-group-or-team" updated: 2026-11-30T16:16:09Z published: 2026-11-30T16:16:09Z canonical: "documentation.sysaid.com/dex-wf-add-user-to-group-or-team" --- > ## Documentation Index > Fetch the complete documentation index at: https://documentation.sysaid.com/llms.txt > Use this file to discover all available pages before exploring further. # Add a User to an M365 Group or Team via Microsoft Graph Resolve the group, verify the user, check existing membership, and add the user idempotently using Microsoft Graph. **Complexity:** Beginner. **Impact:** access-management + group-membership + teams + onboarding + idempotent. ## Why use this workflow Adding users to Microsoft 365 Groups and Teams is one of the most common access-management tasks an IT admin performs. Whether a new hire needs access to a department's Team, a project member needs to join a collaboration group, or an admin needs access for administrative oversight, the workflow is the same: resolve the target group, resolve the user, verify they are not already a member, and then add them. This workflow covers the Microsoft Graph-based approach, which works for both Microsoft 365 Groups (the kind backing Teams, SharePoint sites, and Planner) and pure security groups. It is designed to be **idempotent**: safe to run repeatedly without creating errors or duplicate memberships. Run this workflow whenever you need to grant group-based access in your tenant, or as a building block inside larger onboarding, role-change, or project-provisioning automations. ## Expected outcomes - Identified the correct M365 group or Team by display name, disambiguating between similarly named groups. - Resolved the target user's directory `id` from a UPN, email, or the current signed-in context. - Verified whether the user is already a member, avoiding a `400 Bad Request` on duplicate add. - Added the user to the group with `POST /groups/{id}/members/$ref` (or confirmed no action was needed). - A reusable PowerShell function and a repeatable Graph API pattern that can be dropped into onboarding scripts. ## Risks and considerations - **Dynamic groups:** If the target group has `groupTypes` containing `DynamicMembership`, you cannot add members directly. Membership is rule-driven, and the API returns `400`. Update the membership rule instead. - **On-premises synced groups:** Groups synced from on-premises Active Directory are read-only in Entra ID. Modify them in Active Directory and let the sync run. - **Teams propagation delay:** Adding a user to the underlying M365 group grants Teams access, but the Teams client may take some time to reflect the change. The user may need to restart Teams. - **Ambiguous group names:** Searching for a name such as "Marketing" may return several similarly named groups. Always confirm the group `id` before writing. - **License impact:** If the group is used for group-based licensing, adding a user may consume a license seat. - **Owner vs. member:** This workflow adds *members*. To add an owner, use `/owners/$ref` instead. - **Audit:** All membership changes are logged in the Entra ID audit log. Do not bypass change control for sensitive groups (for example, privileged role-assignable groups). ## Required permissions | Permission | Why it's needed | | --- | --- | | Group.ReadWrite.All | Required to add and remove members on M365 groups and security groups. | | GroupMember.ReadWrite.All | More narrowly scoped alternative to Group.ReadWrite.All for membership-only changes. | | User.Read.All | Required to resolve a user's directory id from a UPN or email address. | | Directory.Read.All | Required to read group properties (groupTypes, mailEnabled, securityEnabled) to validate the target group. | ## Ask Dex Paste the prompt into a Dex conversation. ### Prompt for IT admins ``` Add {user} to the {group_name} M365 group (or Team). First confirm the exact group - if multiple groups match, list them so I can pick. Check whether the user is already a member; if so, tell me and take no action. Otherwise add them and confirm membership. ``` ### How an end user can ask Dex ``` Please add me to the {group_name} team in Teams - I need access to their channels and files. ``` ## Manual steps (admin center) ### Option A: Microsoft 365 admin center (M365 Groups) 1. Sign in to the [Microsoft 365 admin center](https://admin.microsoft.com) as a Global Administrator, User Administrator, or Groups Administrator. 2. Go to **Teams & groups** > **Active teams & groups**. 3. In the search bar, type the group name. Review the results carefully and pick the *exact* group, not a similarly named one. 4. Select the group name to open its details pane. 5. Select the **Members** tab, then select **View all and manage members**. 6. Select **Add members**, search for the user by name or UPN, select them, and select **Add**. 7. Select **Save** (if prompted) and close the pane. ### Option B: Microsoft Entra admin center (any group type) 1. Sign in to the [Microsoft Entra admin center](https://entra.microsoft.com). 2. Go to **Identity** > **Groups** > **All groups**. 3. Search for and select the target group. 4. In the left menu, select **Members**, then select **Add members**. 5. Search for the user, select them, and select **Select**. ### Option C: Microsoft Teams client (Team owners only) 1. Open Microsoft Teams and locate the Team in your list. 2. Select the more options menu next to the Team name, then select **Manage team**. 3. On the **Members** tab, select **Add member**, enter the user, and select **Add**. *Verification:* Refresh the Members list and confirm the user appears. Ask the user to sign out and back in to Teams if the change does not appear immediately. ## Microsoft Graph API The canonical endpoint is `POST /v1.0/groups/{group-id}/members/$ref`. Because this call fails with `400` if the user is already a member, a robust flow resolves IDs and checks membership first. ### Step 1: Resolve the group by display name ``` GET https://graph.microsoft.com/v1.0/groups?$filter=displayName eq '{group_name}'&$select=id,displayName,groupTypes,mailEnabled,securityEnabled ``` Example response: ``` {  "value": [    {      "id": "{group-id}",      "displayName": "{group_name}",      "groupTypes": ["Unified"],      "mailEnabled": true,      "securityEnabled": false    }  ] } ``` If `groupTypes` contains `"DynamicMembership"`, stop. Membership is rule-driven. ### Step 2: Resolve the user ``` GET https://graph.microsoft.com/v1.0/users/{user-upn}?$select=id,displayName,userPrincipalName ``` If the UPN returns 404 (common when a vanity domain is used but the account exists on the `.onmicrosoft.com` suffix), fall back to `GET /v1.0/me` for the signed-in user, or search by `mail`: ``` GET /v1.0/users?$filter=mail eq '{email}' or userPrincipalName eq '{upn}'&$select=id,displayName,userPrincipalName ``` ### Step 3: Check existing membership (idempotency) ``` GET /v1.0/groups/{group-id}/members?$filter=id eq '{user-id}'&$select=id ``` If `value` is non-empty, the user is already a member. Stop here. ### Step 4: Add the member ``` POST https://graph.microsoft.com/v1.0/groups/{group-id}/members/$ref Content-Type: application/json {  "@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/{user-id}" } ``` A successful response is `204 No Content`. Common errors: - `400 One or more added object references already exist`: the user is already a member (safe to ignore). - `403 Insufficient privileges`: missing `Group.ReadWrite.All`, or the group is role-assignable and needs a higher-privileged role. - `400 Unable to update the specified properties for objects that have originated within an external service`: the group is synced from on-premises Active Directory. ### Optional: add as owner instead ``` POST /v1.0/groups/{group-id}/owners/$ref ``` ## PowerShell The `Microsoft.Graph` PowerShell module wraps the Graph endpoints and handles authentication, paging, and retries. Install and connect once: ``` Install-Module Microsoft.Graph -Scope CurrentUser Connect-MgGraph -Scopes "Group.ReadWrite.All","User.Read.All" ``` ### Resolve the group and user ``` # Find the group - inspect results carefully if multiple match $group = Get-MgGroup -Filter "displayName eq '{group_name}'" $user  = Get-MgUser -UserId "{user_upn}" ``` ### Check membership and add ``` $existing = Get-MgGroupMember -GroupId $group.Id -All |    Where-Object { $_.Id -eq $user.Id } if ($existing) {    Write-Host "Already a member - no action taken." } else {    New-MgGroupMember -GroupId $group.Id -DirectoryObjectId $user.Id    Write-Host "Added $($user.UserPrincipalName) to $($group.DisplayName)." } ```