update users in groups when parameter "-RemoveExisting" is used #5147
+49
−19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type
What is in this Pull Request ?
I used this parameter in a project, and wondered why it didn't work.
I discoverd that the parameter "-RemoveExisting" i.e. in function "Add-Microsoft365GroupMember" (and others) was implemented, but completely out of function.
I want to give this PR into a little discussion, because i don't know if i really covered all scenarios in a good way.
Explanation:
While using Add-AzureADGroupe[Member|Owner] as i can see, the code split the input users into guid-users and none guid-users, and add them separately, so i am clearing the group before the both functions are called.
-> Clearing the Owners is not really possible, because there has to be one Owner left on the given group. So my PR could lead into having 2 owners on the group in the end, instead of the only one i want.
With M365Groups it was a bit easier, there i am using the "Update-[Members|Owners]" functions, which first adds not existing Users to the group and delete users, who should not be member of the group.
It is my first work on this project, and therefor i only want to make small changes and give you the possibility to dicuss. I don't want to really get deeper into huge changes, like combining addmembers and adddirectorymembers into one function (if it is even possible)
Guidance
i was using version 3.1.0 of this module and you can reproduce it with any group