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 Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,376 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,515 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Navya 4,000 Reputation points Microsoft Vendor
    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 = "reprouser@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