How to Exclude Blank CountryOrRegion Values in Exchange Online OPATH Filters
Question details
The user needs to configure an OPATH filter for dynamic distribution groups in Exchange Online that successfully excludes recipients with a blank or null CountryOrRegion attribute.

- Product
- Exchange Online
- Device & OS
- not provided
- Scenario
- Creating or updating a dynamic distribution group in Exchange Online to filter out users without a defined country or region.
- Observed behavior
- Excluding recipients requires specific OPATH syntax using both $null and empty string checks, rather than a simple null literal, to function correctly.
Ensure you have the Exchange Online PowerShell module installed and hold the necessary Exchange Administrator permissions to manage dynamic distribution groups.
Use an OPATH Filter to Check for Non-Blank Values
Apply an OPATH filter that explicitly checks that the CountryOrRegion attribute is neither $null nor an empty string.
When filtering in Exchange Online, evaluating empty attributes requires precision. You must verify against both the literal $null variable and an empty string to ensure all blank values are successfully excluded from your dynamic distribution group.
Open PowerShell as an administrator and execute the command Connect-ExchangeOnline to authenticate with your Microsoft 365 tenant.
Format your recipient filter using the syntax: ((CountryOrRegion -ne $null) -and (CountryOrRegion -ne '')).
Run the command Get-Recipient -RecipientPreviewFilter "((CountryOrRegion -ne $null) -and (CountryOrRegion -ne ''))" to preview the list of users and verify that entries with blank regions are excluded.
Use the Set-DynamicDistributionGroup cmdlet with the -RecipientFilter parameter to apply the validated OPATH filter to your group.

Simplify Your Document Management with WPS Office
While managing Exchange Online dynamic distribution groups requires complex PowerShell syntax, handling your daily documents shouldn't be a struggle. WPS Office provides a free, lightweight, and highly compatible alternative to Microsoft Office, giving you a seamless experience for creating and editing Word, Excel, and PowerPoint files without the IT overhead.
- 1. Visit the official website: Navigate to the WPS Office homepage to explore the features.
- 2. Download the installer: Click the Free Download button to get the setup file tailored for your operating system.
- 3. Install and launch: Run the installer, follow the simple on-screen instructions, and start managing your documents with ease.

Frequently Asked Questions
Why doesn't '-ne $null' work by itself in Exchange OPATH filters?
In Exchange Online, an attribute might be stored as an empty string instead of a true null value. To guarantee accurate filtering, you must explicitly exclude both $null and empty strings ('').
How can I preview the members of my Dynamic Distribution Group before saving?
You can use the Get-Recipient -RecipientPreviewFilter cmdlet in PowerShell, passing your OPATH filter string, to view exactly which mailboxes match your criteria before applying it to the group.
Can I use wildcard characters in an OPATH filter for CountryOrRegion?
Yes, you can use the -like or -notlike operators combined with wildcard characters (such as *) to filter recipients based on partial matches in their country or region names.




