Home
Removing all members of a distribution list
Office 365 (PowerShell) Thursday, 04 June 2020 by paul

The following script will remove all members from a Exchange Online distribution list:

# Delete members of a Exchange Online distribution list/group

if ($Session.state -eq 'Broken' -or !$Session) { 
	write-host "Connecting to Exchange Online Powershell.."
	$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential (Get-Credential) -Authentication Basic -AllowRedirection
	Import-PSSession $Session
}

$group = "Groupxxx"

# List distribution group members
Get-DistributionGroupMember -Identity $group | select PrimarySMTPAddress | export-csv backup_list.csv

# Remove all group memebers
$users = Get-DistributionGroupMember -Identity $group
foreach ($user in $users) {
   Remove-DistributionGroupMember -Identity $group -Member $user.DistinguishedName -Confirm:$false
}

After is has completed run a "Get-DistributionGroupMember -Identity $group | select PrimarySMTPAddress" to confirm the group is now empty.


Add Comment
No Comments.