A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
I understand that you are considering preventing members of a specific department from receiving messages sent to a company-wide distribution list or group email.
Regarding Mail Flow (Transport) Rules, this approach might not work well for this requirement. Distribution groups are expanded to all members before transport rules are processed. There is no built-in transport rule action to “remove a specific recipient from delivery.” Transport rules can only act on the entire message (for example: delete, reject, redirect), not on individual recipients after group expansion.
To achieve your goal, I would recommend using a Dynamic Distribution Group.
You can convert (or recreate) your “All Users” group as a DDG. A DDG automatically includes or excludes users based on Azure AD / Exchange attributes such as Department, Custom Attributes, or group membership. This eliminates manual member management, and excluded users are never part of the group expansion.
You can refer via: Create and manage dynamic distribution groups in Exchange Online
You could follow these steps:
Prepare User Attributes
Ensure users have the Department field populated (Go to Microsoft 365 Admin Center portal > Users > [User] > Contact info) or via PowerShell: Using Set-MgUserSet-Mailbox.
For excluding specific individuals (not an entire department), assign a custom attribute, for example: CustomAttribute1 = "ExcludeFromAllUsers".
Next, create (or Convert) to a Dynamic Distribution Group
Go to Exchange Admin Center portal > Recipients > Groups > Select Add a group.
Choose Dynamic distribution group.
Or use Powershell:
# To configure to send All mailboxes except one department
New-DynamicDistributionGroup -Name "All-Users" -DisplayName "All Users" `
-RecipientFilter "((RecipientType -eq 'UserMailbox') -and (-not(Department -eq 'Finance')))"
# Or exclude multiple departments and specific users
New-DynamicDistributionGroup -Name "All-Users" -DisplayName "All Users" `
-RecipientFilter "((RecipientType -eq 'UserMailbox') -and (-not(Department -eq 'Finance')) -and (-not(Department -eq 'HR')) -and (-not(CustomAttribute1 -eq 'ExcludeFromAllUsers')))"
# Alternative: Use an exclusion security group
New-DistributionGroup -Name "All-Users-Exclusions" -Type Security
# Add the specific department members or individuals to this group
New-DynamicDistributionGroup -Name "All-Users" -DisplayName "All Users" `
-RecipientFilter "((RecipientType -eq 'UserMailbox') -and (-not(MemberOfGroup -eq 'All-Users-Exclusions')))"
Test the Configuration
Run:
Get-Recipient -RecipientPreviewFilter (Get-DynamicDistributionGroup "All-Users").RecipientFilter | Select Name, Department, PrimarySmtpAddress
Update Outlook address books, scripts, and any existing processes to use the new Dynamic Distribution Group email address instead of the old static group.
This approach should effectively meet your requirements for “All Staff except specific departments” scenarios.
I hope this helps.
If you have any additional concerns, feel free to comment below. I would be more than happy to assist.
Note: Please follow the steps in [our documentation] to enable e-mail notifications if you want to receive the related email notification for this thread.