Hi,
I am new to Exchange online and learning as I use it. One thing I have noticed is that Microsoft does not have any type of function to "Remove / Remove All" when looking at the Exchange properties of a user account and then under "Member Of" for distro groups. Now I have a Powershell script that allows me to do so but I am having difficulty running in. I've seen it used before and it was a much easier / quicker method to remove a user from all distro groups (which is what I need to do).
As for the easiest method (delete the mailbox / user account in Exchange), that's not an option for me even though these accounts are not in use anymore. Here is the code, maybe I have something wrong.
$user = $args[0]if (!$args[0]) {
}
$mailbox=get-mailbox $user
$dgs= Get-DistributionGroup
foreach($dg in $dgs){
$DGMs = Get-DistributionGroupMember -identity $dg.Identity
foreach ($dgm in $DGMs){
if ($dgm.name -eq $mailbox.name){
write-host 'User Found In Group' $dg.identity
Remove-DistributionGroupMember $dg.Name -Member $user
}
}
}