Delete User from Group

Modified on Tue, 30 Jun at 3:16 PM

    # Define the path to your CSV file

    $csvFilePath = "C:\temp\del-mem.csv"


    # Import the CSV file

    $membersToRemove = Import-Csv -Path $csvFilePath


    # Iterate through each entry in the CSV

    foreach ($entry in $membersToRemove) {

        $dlName = $entry.DLName

        $memberEmail = $entry.MemberEmail


        # Remove the member from the distribution group

        try {

            Remove-DistributionGroupMember -Identity $dlName -Member $memberEmail -Confirm:$false

            Write-Host "Removed $($memberEmail) from $($dlName)."

        }

        catch {

            Write-Warning "Failed to remove $($memberEmail) from $($dlName): $($_.Exception.Message)"

        }

    }

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article