Microsoft 365: PowerShell to Remove a user from All Distribution Groups

Requirement: Remove a user account from all distribution lists in Office 365.

How to remove a user from All Distribution Groups?

In Office 365, distribution groups are used to send emails to a group of people. This is especially helpful for team projects, announcements, or any other situation where sending emails to multiple people is necessary. However, managing these groups can be a bit tricky. In some cases, you may want to remove a user from all distribution groups for various reasons. For example, if a user is no longer with your organization, you may want to remove them from all distribution groups, so they don’t receive any emails. Fortunately, you can remove a user from all distribution groups in Office 365 using PowerShell. In this article, we’ll show you how to do this.

How to Remove a User from a Distribution Group in Microsoft 365?

If you need to remove a user from a distribution group in Microsoft 365, there are a few different ways you can do it. Let me show you how to remove a user from a distribution group using the Microsoft 365 admin center. BTW, to remove a user from a distribution group in Microsoft 365, you’ll need to be a Microsoft 365 administrator or a user with the appropriate permissions.

To remove a user from a distribution group using the Microsoft 365 admin center, follow these steps:

  1. Log in to the Microsoft 365 admin center at https://admin.microsoft.com.
  2. Click on the “Active teams & groups” link under the “Teams & groups” tab.
  3. Select the distribution list tab >> Select the distribution group from which you want to remove the user.
  4. Click on the Members tab >> Select the “View all and manage members” link.
    how to remove user from distribution list
  5. Select the user you want to remove from the distribution group >> From the command bar, click on the little three dots and choose “Remove Members”.
    remove users from distribution group microsoft 365

PowerShell is a powerful scripting language that provides an efficient way of automating tasks in Windows environments. It can be used to automate various administrative tasks, including removing users from distribution lists. In this article, we will discuss how to write a PowerShell script to remove users from all distribution lists.

Office 365: PowerShell to Remove a user from Distribution list

Here is how to remove a user from a distribution list in Office 365 using PowerShell with Remove-DistributionGroupMember cmdlet:

#Parameters
$GroupEmailID = "[email protected]"
$UserEmailID = "[email protected]"

#Connect to Exchange Online
Connect-ExchangeOnline -ShowBanner:$False

#office 365 PowerShell to Remove a user from Distribution list
Remove-DistributionGroupMember –Identity $GroupEmailID -Member $UserEmailID -Confirm:$false

PowerShell to Remove user from All Distribution Groups

If you need to remove a user from all distribution groups in your Office 365 tenant, you can do so using PowerShell. This process is relatively simple and only requires a few steps. In this article, we’ll show you how to remove a user from all distribution groups in Office 365 using PowerShell.

  1. To start with, You must connect to Office 365 using PowerShell. This script prompts you to connect to Exchange Online. When prompted, enter your Office 365 username and password.
  2. Once connected to Office 365, it gets all distribution groups.
  3. You can search each group to check if the given user is a member of the group.
  4. If yes, you can remove a User from the particular distribution group.
$UserToRemove = "[email protected]"

Try {
    #Connect to Exchange Online
    Connect-ExchangeOnline

    #Get All Distribution Lists - Excluding Mail enabled security groups
    $DistributionGroups = Get-Distributiongroup -resultsize unlimited |  Where {!$_.GroupType.contains("SecurityEnabled")}

    #Loop through each Distribution Lists
    ForEach ($Group in $DistributionGroups)
    {
        #Check if the Distribution List contains the particular user
        If ((Get-DistributionGroupMember $Group.Name | Select -Expand PrimarySmtpAddress) -contains $UserToRemove)
        {
            Remove-DistributionGroupMember -Identity $Group.Name -Member $UserToRemove -Confirm:$false
            Write-host "Removed user from group '$Group'" -f Green
        }
    }
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}

This script will remove the user from all distribution groups. Make sure you replace the $UserToRemove with the user you want to remove.

How about removing all users from a distribution group?

#Parameters
$GroupEmailID = "[email protected]"

#Connect to Exchange Online
Connect-ExchangeOnline -ShowBanner:$False

#Get All Members from a Distribution list
$DistributionGroupMembers = Get-DistributionGroupMember $GroupEmailID

#Remove All users from the distribution list
ForEach ($Member in $DistributionGroupMembers)
{
    Remove-DistributionGroupMember -Identity $GroupEmailID –Member $member.name -Confirm:$false
    Write-host -f Green "Removed user:" $Member.PrimarySmtpAddress
}

In conclusion, PowerShell provides an easy way to automate tasks and remove users from distribution lists. By writing a simple script, administrators can save time and effort in removing users from multiple distribution lists.

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *