Powersehll Beginner - Add multiple Users to group

%3CLINGO-SUB%20id%3D%22lingo-sub-1626944%22%20slang%3D%22de-DE%22%3EPowersehll%20Beginner%20-%20Add%20multiple%20Users%20to%20group%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1626944%22%20slang%3D%22de-DE%22%3E%3CP%3EHello%2C%20I%20am%20a%20Powershell%20beginner.%20I'm%20responsible%20for%20user%20maintenance%20in%20Microsoft%20365%20at%20our%20school%20and%20have%20to%20prepare%20the%20approximately%201000%20students%20and%20100%20teachers%20in%20such%20a%20way%20that%20teams%20are%20created%20as%20easily%20as%20possible.%20Due%20to%20the%20Corona%20situation%20we%20were%20put%20in%20this%20position%20from%20now%20on.%20Unfortunately%20our%20school%20-%20like%20so%20many%20others%20-%20does%20not%20have%20professional%20IT%2C%20so%20this%20work%20is%20done%20%22on%20the%20side%22.%20%3CBR%20%2F%3E%20I%20have%20tried%20to%20create%20class%20groups%20for%20the%20new%20school%20year%20where%20no%20teachers%20have%20been%20assigned%20yet.%20The%20teachers%20should%20decide%20for%20themselves%20whether%20a%20team%20is%20created%20or%20not.%20With%20SchoolDataSync%20the%20creation%20of%20the%20groups%20worked%2C%20but%20the%20groups%20all%20have%20the%20parameter%20%22HiddenGroupMemmbershipEnabled%22%20and%20only%20the%20group%20owner%20can%20create%20a%20team.%20%3CBR%20%2F%3E%20I%20did%20not%20find%20a%20way%20to%20change%20this%20parameter.%20%3CBR%20%2F%3E%20In%20Powershell%20I%20tried%20to%20fill%20a%20manually%20created%20group%20with%20users%20using%20a%20simple%20script.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EImport-csv%20C%3A%5Ctemp%5Cgroups.csv%0AImport-Csv%20C%3A%5Ctemp%5Cgroups.csv%20%7C%20ForEach-Object%20%7BAdd-ADGroupMember%20-Identity%20%24_.groupname%20-Members%20%24_.username%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20unfortunately%20I%20get%20the%20following%20error%2C%20which%20overtaxes%20me%20as%20a%20beginner.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3Eusername%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20groupname%0A--------%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20---------%0Axxx.bu%40mariengym-jev.de%20%20%20%20%20%20%20%20%20%20%20Gtest20%20%20%0Axxx.cardo.santos%40mariengym-jev.de%20Gtest20%20%20%0Axxx.corn%40mariengym-jev.de%20%20%20Gtest20%20%20%0Axxx.eil%40mariengym-jev.de%20%20%20%20%20%20%20%20%20Gtest20%20%20%0Axxx.eile%40mariengym-jev.de%20%20%20%20%20%20%20%20%20%20Gtest20%20%20%0AAdd-ADGroupMember%20%3A%20Es%20wurde%20kein%20Standardserver%20gefunden%2C%20auf%20dem%20die%20Active%20Directory-Webdienste%20ausgef%C3%BChrt%20werden.%0AIn%20C%3A%5Ctemp%5Cgroups_import_sus.ps1%3A2%20Zeichen%3A49%0A%2B%20...%20ach-Object%20%7BAdd-ADGroupMember%20-Identity%20%24_.groupname%20-Members%20%24_.user%20...%0A%2B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%0A%20%20%20%20%2B%20CategoryInfo%20%20%20%20%20%20%20%20%20%20%3A%20ResourceUnavailable%3A%20(Gtest20%3AADGroup)%20%5BAdd-ADGroupMember%5D%2C%20ADServerDownException%0A%20%20%20%20%2B%20FullyQualifiedErrorId%20%3A%20ActiveDirectoryServer%3A1355%2CMicrosoft.ActiveDirectory.Management.Commands.AddADGroupMember%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20a%20school%2C%20we%20actually%20need%204%20scripts%20to%20be%20able%20to%20cope%20with%20everyday%20life%20and%20the%20school%20year%3A%3C%2FP%3E%3CP%3E1.%20A%20script%20to%20create%20many%20groups%20(at%20each%20school%20year%20change).%20%3CBR%20%2F%3E%202.%20A%20script%20to%20assign%20the%20users%20to%20the%20groups.%20%3CBR%20%2F%3E%203.%20A%20script%20to%20create%20new%20students.%20%3CBR%20%2F%3E%204.%20A%20script%20to%20remove%20students%2Fusers%20who%20have%20left%20the%20school.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20should%20always%20be%20done%20with%20CSV%20files%20if%20possible.%3C%2FP%3E%3CP%3EOr%20are%20there%20other%20possibilities%20for%20schools%3F%20Sorry%2C%20here%20in%20Germany%20we%20are%20unfortunately%20still%20at%20the%20very%20beginning%20with%20Micrsoft%20teams.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20grateful%20for%20any%20help%20-%20please%20also%20tell%20me%20if%20this%20is%20the%20wrong%20place%20to%20ask%20and%20I%20should%20better%20ask%20at%20another%20place.%3C%2FP%3E%3CP%3EBest%20regards%20%3CBR%20%2F%3E%20Axel%20Rumkorf%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1626944%22%20slang%3D%22de-DE%22%3E%3CLINGO-LABEL%3EMicrosoft%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1627491%22%20slang%3D%22en-US%22%3ERe%3A%20Powersehll%20Beginner%20-%20Add%20multiple%20Users%20to%20group%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1627491%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F772971%22%20target%3D%22_blank%22%3E%40AxelRumkorf%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBased%20on%20the%20fact%20that%20you%20are%20a%20beginner%20Powershell%2C%20and%20that%20you%20need%20an%20easy%20way%20to%20fix%20this%2C%20I%20suggest%20you%20take%20a%20look%20at%20%3CA%20href%3D%22https%3A%2F%2Femea.flow.microsoft.com%2Fen-us%2Fconnectors%2Fshared_azuread%2Fazure-ad%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EPower%20Automate%20and%20the%20Azure%20AD%20connector%3C%2FA%3E.%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20easily%20create%20users%20based%20on%20CSV%20lists%2C%20and%20add%20them%20to%20groups%2Fteams%20as%20well.%3C%2FP%3E%3CP%3EAlso%2C%20take%20a%20look%20at%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Factive-directory%2Fusers-groups-roles%2Fgroups-dynamic-membership%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Edynamic%20groups%3C%2FA%3E.%20You%20can%20create%20groups%20based%20on%20AAD%20properties%2C%20such%20as%20department%2C%20job%20title%2C%20and%20location.%20This%20can%20also%20be%20used%20for%20on-%20and%20offboarding.%20Just%20by%20changing%20the%20property%20of%20the%20users%2C%20the%20group%20membership%20will%20be%20updated.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThese%20blog%20posts%20will%20get%20you%20started%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.c-sharpcorner.com%2Farticle%2Fcreate-user-in-azure-ad-and-assign-office-365-licenses-using-power-automate%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.c-sharpcorner.com%2Farticle%2Fcreate-user-in-azure-ad-and-assign-office-365-licenses-using-power-automate%2F%3C%2FA%3E%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Femea.flow.microsoft.com%2Fen-us%2Fgalleries%2Fpublic%2Ftemplates%2F92a7b1a473a14737afe1c67abb9629fa%2Fcreate-azure-ad-user-from-sharepoint-list%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Femea.flow.microsoft.com%2Fen-us%2Fgalleries%2Fpublic%2Ftemplates%2F92a7b1a473a14737afe1c67abb9629fa%2Fcreate-azure-ad-user-from-sharepoint-list%2F%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New 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
Highlighted

@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...