Forum Discussion
Sean Vriesen
Jun 26, 2019Copper Contributor
Cloning O365 Group Memberships
I'm interested in replicating the O365 group memberships of a given user for another user. By this I mean adding a user to the same set of groups in which a given user is currently a member. The us...
- Jun 27, 2019
That depends on the specifics I guess. Here's a quick sample of what you can do with PowerShell.
List all groups a given user is a member of:
$dn = (Get-Mailbox user).DistinguishedName Get-Recipient -Filter "Members -eq '$dn'"
Use the above list to add another user as member:
Get-Recipient -Filter "Members -eq '$dn'" | % { Add-DistributionGroupMember $_.Name -Member anotheruser}
That's a really basic code though and it assumes that all the groups are distribution ones. A bit more complex one will check the actual type and use the corresponding cmdlet:
$dn = (Get-Mailbox user).DistinguishedName Get-Recipient -Filter "Members -eq '$dn'" -RecipientTypeDetails GroupMailbox | % { Add-UnifiedGroupLinks $_.Name -LinkType Member -Links anotheruser } Get-Recipient -Filter "Members -eq '$dn'" -RecipientTypeDetails MailUniversalDistributionGroup | % { Add-DistributionGroupMember $_.Name -Member anotheruser }
Sean Vriesen
Jun 26, 2019Copper Contributor
Thanks! I think the PowerShell option is the more desirable one at the moment.
I'm still a novice with PowerShell, though eagerly learning all I can. Could you help me out with the code I should use?
Thanks much!
I'm still a novice with PowerShell, though eagerly learning all I can. Could you help me out with the code I should use?
Thanks much!
Jun 26, 2019
Well, I could probably figure it out using the unifiedgroup and unifiedgrouplinks cmdlets but I’d hear with VasilMichev first! Maybe he got something in stock