In a recent project, we needed to updated members of an existing Office 365 group using Microsoft Graph Client CSOM. Previously in a blog here, I have listed a way to add members using Office 365 PnP CSOM (UnifiedGroupUtility) but there is an ongoing issue with it in the recent releases . So in the meantime while that issue is fixed, we could use the below method to update owners or members in O365 groups.
- Create a Graph app. The steps for doing that is listed in this blog.
- Get the Authentication token of the App
- Get the list of owner emails and add them to a list array
- Call the Graph Client to authenticate using the authentication token
- Traverse the owners emails array and validate the user using the Graph users collection
- Add the user to the members and owners of the Office 365 group
Note: For Office 365 group owners, the users should be a part of the members and the owners groups.
Below is the code snippet for the same.
Happy Coding !!!