Remove a Office 365 User/Mailbox from all distribution lists

Remove all groups on a user with Powershell;
# Get the correct mailbox
$mbx = ( Get-Mailbox UserPrincipalName )

# Process all DistributionGroups and if mailbox is member remove (with simple console output)
foreach ($group in Get-DistributionGroup -ResultSize unlimited) {
 if ((Get-DistributionGroupMember $group.identity | select -Expand distinguishedname) -contains $mbx.DistinguishedName){
  write-host "Removing user from" $
  Remove-DistributionGroupMember $ -member $mbx.DistinguishedName -BypassSecurityGroupManagerCheck -confirm:$false

1 comment:

Unknown said...

Office 365 is one of the important services of Microsoft, which is actually a group of software plus service subscriptions that provide services to its subscribers with the advance productive software. It actually itself run the applications of MS Office on Windows and OS X both and provide its own secure storage space on cloud storage service and also grants 60 Skype minutes every month. MS Office 365 is designed especially for a very small businesses to large international businesses.
Office 365 Technical Support