Jan 30, 2021 1 min read

PowerShell: remove all subscriptions on a Microsoft 365 group

PowerShell script to remove subscriptions from a Microsoft 365 Group.

PowerShell: remove all subscriptions on a Microsoft 365 group

A user can subscribe to a Microsoft 365 Group, or this can be done automatically by an administrator in a company. In that case, all group mails and group calendar events will be delivered to both the group mailbox AND the user mailbox.
Groups created through Microsoft Teams have this setting "off" by default, so new members don't get subscribed automatically. This works perfectly for groups with manually managed membership, but goes wrong when using dynamic group membership. For some reason, any new member in my dynamic groups will always be subscribed even with the auto-subscribe toggle turned off 🤯.

Until Microsoft fixes this (I will log a ticket!), I regularly run a PowerShell script for these groups with dynamic membership rules:

$Team = "MyTeam"
$Members = Get-UnifiedGroupLinks -LinkType Members -Identity $Team
Foreach ($Member in $Members) {
    Remove-UnifiedGroupLinks -LinkType Subscribers -Links $Member.PrimarySmtpAddress -Identity $Team -Confirm:$false
}

You will need the Exchange Online Management PowerShell module installed, and then the script will do the following:

  • Get all members from a specific Group/Team. Update the $Team variable with the mailNickname of the Group you want to adjust.
  • Loop over each member and remove that member as a subscriber

BOOM DONE! That simple 😃.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Yannick Reekmans.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.