Delete multiple members of distribution group using CSV thru Exchange Management Shell On Premise

Gatchalian, AD 25 Reputation points
2023-03-02T02:49:39.17+00:00

I received a request from our employees to delete all the members of this particular distribution group within our organization, and upon checking this DL has a total of 7,000 members.

Is there any powershell script I can use to delete just the members of this DL?

Thank you,

AD

Exchange Server
Exchange Server
A family of Microsoft client/server messaging and collaboration software.
1,342 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,675 questions
Microsoft Exchange
Microsoft Exchange
Microsoft messaging and collaboration software.
567 questions
Excel Management
Excel Management
Excel: A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.Management: The act or process of organizing, handling, directing or controlling something.
1,728 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,605 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Manu Philip 18,681 Reputation points MVP
    2023-03-02T03:47:35.7233333+00:00

    You may try the following PS script

    $memberlist = Get-DistributionGroupMember -Identity <dl name>
    $memberlist | % {Remove-DistributionGroupMember -Identity <dl name> -Member $_.Name -Confirm:$false} 
    

    --please don't forget to upvote and Accept as answer if the reply is helpful--

    1 person found this answer helpful.

  2. Rich Matheisen 46,896 Reputation points
    2023-03-02T19:33:44.58+00:00

    Try this:

    $DLName = "MyDL"
    Get-DistributionGroupMember -Identity $DLName> -Resultsize Unlimited |
        ForEach-Object{
            Try{
                Get-ADUser $_.Identity -ErrorAction Stop    # if there's no AD user don't try to remove it
                $_ | Remove-DistributionGroupMember -Identity $DLName -Member $_.Identity -Confirm:$false
            }
            Catch{
                # log some information?
            }
        }
    
    

    NOTE: I haven't tried running this code!!!!!

    0 comments No comments

  3. Hilton, Brett 0 Reputation points
    2024-10-29T15:39:40.9266667+00:00

    To delete all members of a DL, just use this:

    update-distributiongroupmember "DL Email address" -members $null

    This will remove all members of the list. To confirm the deletion, use this command:

    Get-DistributionGroupMember "DL Email address").member.count

    Or use this: (Get-ADGroup "DL Email address" -Properties *). Member. Count

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.