Assign Group to users massively

Fiammenghi Fabrizio 46 Reputation points
2020-04-18T13:33:36.43+00:00

Hi,
i'm writing on behalf of a friend, that due to coronvirus has been "elected" as one of administraotr of Microsoft for school plan A1.
Unfortuantely he has been involved, once the user had been already created on the tenant.
they have more 600 users divied in teacher, student and external collaborator.
Unfortunately the company who created the user, did not create any AD group to divide them , but they :

  1. follow this rule when creating account :
    ******@schoolname.com where
    xxx is "d" if the user is a teacher
    xxx is "s" if the user is a student
    xxx is "ose" if the user is an external collaborator
  2. The "title" (or role) field contains "Teacher", "Student", "Collaborator" based on the user

He would like to create 3 different AD Group "Teacher", "Student", "Collaborator", but in the user management , he cannot find a way to filter the users based on xxx@schoolname criteria , or sort/filter based on title or role (that is an available display column), so he can select part of the users and massively assign a group.

he has to select one by one , and ufortunatey the users are sorteb by name, so it is a big mess.

is there a way to apply the filter or sorting based on art of the account name ot title ?
is there a way with powershell to do it ?

thanks in advance

Fabrizio

Microsoft Entra
0 comments No comments
{count} vote

Accepted answer
  1. thgibard-MSFT 356 Reputation points
    2020-04-19T11:47:05.583+00:00

    Yes, currently if you want to do it in a large range you will need to do it thanks to PowerShell.

    In this scenario, you can use the PowerShell module called AzureAD and use the following CmdLine to be able to add members to your Azure AD Group : https://learn.microsoft.com/fr-fr/azure/active-directory/users-groups-roles/groups-settings-v2-cmdlets. Azure AD module can be installed easily by typing the command : Install-Module AzureAD from any server that is able to reach Internet. Then, you can see all the available commands by doing the command : Get-Command -Module AzureAD and the CmdLet that will be useful for you will be : Add-AzureADGroupMember. Are you confortable with PowerShell ?

    1 person found this answer helpful.
    0 comments No comments

9 additional answers

Sort by: Most helpful
  1. Fiammenghi Fabrizio 46 Reputation points
    2020-04-21T00:21:17.42+00:00

    Hi @thgibard-MSFT ,
    pls note that i found the solution.
    the script to use is :

    $users = Get-AzureADUser -All $true | Where-Object{($_.UserPrincipalName -like '*******@schoolname.com')}
    foreach ($user in $users) {
    Add-AzureADGroupMember -ObjectId "{the ObjectId of the Teacher Group}" -RefObjectId $user.ObjectId
    }

    Fabrizio


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.