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,173 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,468 questions
Microsoft Exchange
Microsoft Exchange
Microsoft messaging and collaboration software.
446 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,685 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,274 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Manu Philip 17,266 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--


  2. Rich Matheisen 45,596 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