Powersehll Beginner - Add multiple Users to group

Copper Contributor

Hello, I am a Powershell beginner. I'm responsible for user maintenance in Microsoft 365 at our school and have to prepare the approximately 1000 students and 100 teachers in such a way that teams are created as easily as possible. Due to the Corona situation we were put in this position from now on. Unfortunately our school - like so many others - does not have professional IT, so this work is done "on the side".
I have tried to create class groups for the new school year where no teachers have been assigned yet. The teachers should decide for themselves whether a team is created or not. With SchoolDataSync the creation of the groups worked, but the groups all have the parameter "HiddenGroupMemmbershipEnabled" and only the group owner can create a team.
I have not found a way to change this parameter.
In Powershell I tried to fill a manually created group with users using a simple script.

 

 

Import-csv C:\temp\groups.csv
Import-Csv C:\temp\groups.csv | ForEach-Object {Add-ADGroupMember -Identity $_.groupname -Members $_.username}

 

 

But unfortunately I get the following error, which overtaxes me as a beginner.

 

username                              groupname
--------                              ---------
xxx.bu@mariengym-jev.de           Gtest20  
xxx.cardo.santos@mariengym-jev.de Gtest20  
xxx.corn@mariengym-jev.de   Gtest20  
xxx.eil@mariengym-jev.de         Gtest20  
xxx.eile@mariengym-jev.de          Gtest20  
Add-ADGroupMember : Es wurde kein Standardserver gefunden, auf dem die Active Directory-Webdienste ausgeführt werden.
In C:\temp\groups_import_sus.ps1:2 Zeichen:49
+ ... ach-Object {Add-ADGroupMember -Identity $_.groupname -Members $_.user ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (Gtest20:ADGroup) [Add-ADGroupMember], ADServerDownException
    + FullyQualifiedErrorId : ActiveDirectoryServer:1355,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember

 

 

As a school, we actually need 4 scripts to be able to cope with everyday life and the school year:

1. A script to create many groups (at each school year change).
2. A script to assign the users to the groups.
3. A script to create new students.
4. A script to remove students/users who have left the school.

 

This should always be done with CSV files if possible.

Or are there other possibilities for schools? Sorry, here in Germany we are unfortunately still at the very beginning with Micrsoft teams.

 

I am grateful for any help - please also tell me if this is the wrong place to ask and I should better ask at another place.

Best regards
Axel Rumkorf

1 Reply

@AxelRumkorf 

 

Based on the fact that you are a beginner Powershell, and that you need an easy way to fix this, I suggest you take a look at Power Automate and the Azure AD connector

You can easily create users based on CSV lists, and add them to groups/teams as well.

Also, take a look at dynamic groups. You can create groups based on AAD properties, such as department, job title, and location. This can also be used for on- and offboarding. Just by changing the property of the users, the group membership will be updated. 

 

These blog posts will get you started:

https://www.c-sharpcorner.com/article/create-user-in-azure-ad-and-assign-office-365-licenses-using-p...

https://emea.flow.microsoft.com/en-us/galleries/public/templates/92a7b1a473a14737afe1c67abb9629fa/cr...