Forum Discussion
JanE40
Feb 03, 2025Copper Contributor
Exchange Online: New-Addresslist with RecipientFilter
Hello,
our client will move from OnPrem Exchange to Cloud, i just set up an hybrid connection where everything works fine so far.
I wanted to migrate the custom address lists from OnPrem to Online by rebuilding them with powershell. Our client has some companies and wants address lists for every company. They all have different domains so i want to create new address lists based on the UPNs.
I tested with Get-Recipient -Filter and got the results i wanted, so i just used the same filter in New-Addresslist and don't get any results...what am i missing?
Get-Recipient -Filter {((RecipientTypeDetails -eq 'UserMailbox') -or (RecipientTypeDetails -eq 'MailUser') -and (UserPrincipalName -like '*contoso.com') -and (HiddenFromAddressListsEnabled -eq 'False'))}
// this gets me the results i wanted
New-Addresslist -Name "Contoso" -RecipientFilter {((RecipientTypeDetails -eq 'UserMailbox') -or (RecipientTypeDetails -eq 'MailUser') -and (UserPrincipalName -like '*contoso.com') -and (HiddenFromAddressListsEnabled -eq 'False'))}
// this creates an empty address list
Few things. First, you should use -RecipientPreviewFilter instead of filter, but that's minor. Next, you should be grouping your conditions, as otherwise the logic gets distorted. In your example, the first two conditions need another () group.
{(((RecipientTypeDetails -eq 'UserMailbox') -or (RecipientTypeDetails -eq 'MailUser')) -and (UserPrincipalName -like '*contoso.com') -and (HiddenFromAddressListsEnabled -eq 'False'))}
Another thing to note is that the UserPrincipalName property is not available for all recipients and cmdlets. Should not be a problem in this specific example, but adding it just in case.
Lastly, there's an extra step you need to perform in Exchange Online, namely "touch" objects before they appear in new/modified address lists. In other words you need to change any property on said objects. It's explained in the article Dan linked below.
Few things. First, you should use -RecipientPreviewFilter instead of filter, but that's minor. Next, you should be grouping your conditions, as otherwise the logic gets distorted. In your example, the first two conditions need another () group.
{(((RecipientTypeDetails -eq 'UserMailbox') -or (RecipientTypeDetails -eq 'MailUser')) -and (UserPrincipalName -like '*contoso.com') -and (HiddenFromAddressListsEnabled -eq 'False'))}
Another thing to note is that the UserPrincipalName property is not available for all recipients and cmdlets. Should not be a problem in this specific example, but adding it just in case.
Lastly, there's an extra step you need to perform in Exchange Online, namely "touch" objects before they appear in new/modified address lists. In other words you need to change any property on said objects. It's explained in the article Dan linked below.
- JanE40Copper Contributor
Touching the objects to force a change did it! Thank you!
I just added a description text for all users and did an Entra sync and all users immediately appeared in the addess list as wished.