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.