How to BULK GROUPS to a User

John Corporal 0 Reputation points
2024-04-17T00:55:26.9633333+00:00

Hello,

As part of our onboarding process we are required to create user accounts in Microsoft admin center. Once created, we need to add this user to multiple different groups. The process to do this in the admin center is incredibly frustrating and is driving me crazy! To add each group I have to type in the search field and add EACH GROUP MANUALLY. This is an incredibly inefficient and archaic process. Some users have almost 20-30 groups that they need to be added to! I have a list of group memberships that need to be added to each profile type. Is there a way where I can add multiple groups at once? With on-prem AD in the past I could just copy and paste all groups into the user profile and it would be validated and applied all at once. Is there a way to do this in the admin center or even Azure AD? Is there a Powershell script that can do this?

Please help!

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Entra | Microsoft Entra ID
{count} votes

1 answer

Sort by: Most helpful
  1. Navya 20,100 Reputation points Microsoft External Staff Moderator
    2024-04-17T11:42:09.6+00:00

    @John Corporal

    Thank you for posting this in Microsoft Q&A.

    I understand you want to add multiple groups to a user.

    Yes, there is a way to add multiple groups to a user account at once using PowerShell.

    Below is the PowerShell script.

    Creates a CSV file named GroupsList.csv that includes a column for GroupNames

    Install-Module AzureAD
    Import-Module AzureAD
    Connect-AzureAD
    $userUPN = "******@r.onmicrosoft.com"
    $csvFilePath = "C:\customroles\GroupsList.csv"
    $groupNames = Import-Csv -Path $csvFilePath | Select-Object -ExpandProperty GroupNames
    foreach ($groupName in $groupNames) {
        Add-AzureADGroupMember -ObjectId (Get-AzureADGroup -Filter "DisplayName eq '$groupName'").ObjectId -RefObjectId (Get-AzureADUser -ObjectId $userUPN).ObjectId
    }
    

    Hope this helps. Do let us know if you any further queries.

    Thanks,

    Navya.

    If the answer is helpful, please click "Accept Answer" and kindly "upvote" it.

    0 comments No comments

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.