Exchange Online create custom address list filter by email

berketjune2012 351 Reputation points
2021-09-22T15:50:06.61+00:00

Hello

I would like to create a custom address list "New List" in Exchange online and add any users with a specific domain such as @Company portal .com in their email address.

And then verify the members of the list?

What would be the powershell command ?

Thanks

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,177 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Vasil Michev 95,341 Reputation points MVP
    2021-09-22T17:42:01.82+00:00

    New-AddressList, then specify the name and recipient filter to use. For example, you can use a filter like this:

    ((Alias -ne $null) -and (EmailAddresses -like '*@keyman .com'))

    For additional details and examples, refer to the official documentation here: https://learn.microsoft.com/en-us/exchange/address-books/address-lists/manage-address-lists
    Make sure you also check the section about updating lists, as in ExO this requires you to "touch" each object.

    0 comments No comments

  2. Yuki Sun-MSFT 40,856 Reputation points
    2021-09-23T06:21:33.313+00:00

    Hi @berketjune2012 ,

    According to this official document, it's not supported to use the wildcard as a prefix for the RecipientFilter parameter in Exchange Online Powershell, so it's not feasible to use recipient filter like (EmailAddresses -like '*@keyman .com') to directly create the customized address list.

    As a workaround, we can set one of the custom attribute for the mailboxes who have PrimarySmtpAddress with specific domain such as @Company portal .com, for example:

    Get-Mailbox | Where{$_.RecipientType -eq 'UserMailbox' -and $_.PrimarySmtpAddress -like "*contoso.com"} | Set-Mailbox -CustomAttribute10 "DomainContoso"  
    

    Then the custom address list can be created based on the conditional custom attribute:

     New-AddressList -Name "DomainContoso AddressList" -IncludedRecipients AllRecipients -ConditionalCustomAttribute10 "DomainContoso"  
    

    To view the members of the address list, run the command below:

    $AL = Get-AddressList -Identity "DomainContoso AddressList"; Get-Recipient -ResultSize unlimited -RecipientPreviewFilter $AL.RecipientFilter | select Name,PrimarySmtpAddress,HiddenFromAddressListsEnabled  
    

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    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.