Hello @Fiammenghi Fabrizio
The problem is - it's quite complicated to help you if I can't see/understand the exact configuration that you have in your Tenant (name of the groups concerned, users that you want to add, etc.). And you cannot obviously display all these details in a public forum.
However, I've done a small example on my personal environment and here more details that you can use :
1) You will do that in PowerShell. The module AzureAD must be installed. You can do that on your personal Laptop/Desktop or on a server : no constraint on that. So, install the module with the following command and accept by clicking Yes when prompted : Install-Module AzureAD.
2) Then, you will need to connect in PowerShell to your O365/Azure AD environment. To do so, you will use the following command : Connect-AzureAD. When you will press Enter, you will be prompted to authenticate yourself to your O365 Tenant.
3) After, you can try a few commands : Get-AzureADUser will give you in PowerShell the list of your users. Get-AzureADGroup will give you the list of your groups.
4) To be able to add members to a specific Azure AD Group, you will need to use the following command : Add-AzureADGroupMember -ObjectId ccb09ffc-10aa-41be-a5b3-19aaf34f8c1d -RefObjectId 9642cb71-fa91-437d-aba1-1306b8b0b7de
The first parameter ObjectID is the unique identifier for your Azure AD Group. The second parameter RefObjectId is the unique iD for the USER that you want to be a member of this group.
Finally, this unique command will obviously add 1 guy to 1 group. In your scenario, you want to do a massive add - so there will certainly be a ForEach loop somewhere and if you want to take in account the extension XXX that you have in your emails (for teachers, students, etc.) - you will probably need a few IF statements.
But without seeing everything, I can't go deeply in details.
thgibard.