2

Are wildcards supported in Exchange Online PowerShell cmdlets? I want to create a new Address List which filters by Mail address but cannot get it to work.

The following command yields no results even though there are users with such a mail address:

Get-Recipient -Filter {(Alias -ne $null) -and (PrimarySmtpAddress -like '*@domain.com')}

When I type in the whole mail address by hand it returns a result, so it is clear that the wildcard filter does not work.

So are wildcards not supported? If that is the case, then why does the following command return results when filtering mail contacts?

Get-Recipient -Filter {(Alias- ne $null) -and (ExternalEmailAddress -like '*@domain.com')}
2
  • Your post is missing the closing brace (aka curly bracket). Did you have that when you ran the command? This exact syntax worked for me when I ran it in my environment using my domain name.
    – Sam Erde
    Nov 13, 2020 at 3:51
  • Hi, it's been a long time, is there any update? If the below answers are helpful to you, you could mark the best answer. Have a nice day:-)
    – Ivan_Wang
    Nov 25, 2020 at 1:52

2 Answers 2

1

Part of the problem that you may be running into is that some attributes are not usable with the -Filter parameter of the Get-Recipient command. For example:

Get-Mailbox -Filter {(Alias -ne $null) -and (ExternalEmailAddress -like '*@example.com')}

Results in:

Cannot bind parameter 'Filter' to the target. Exception setting "Filter": ""ExternalEmailAddress" is not a recognized filterable property. For a complete list of filterable properties see the command help.

One way you can get around this takes longer to process, but works: get all recipients that have an alias, and then use the Where function to process the 2nd part of your query. The resulting command set would look like this:

(Get-Recipient -Filter {(Alias -ne $null)} -ResultSize Unlimited).Where{$_.EmailAddresses -like "*example.com"}

Using the above Where method gives you the same results as piping to the Where-Object cmdlet, but is faster. The following syntax will provide the same results:

Get-Recipient -Filter {(Alias -ne $null)} -ResultSize Unlimited | Where-Object {$_.EmailAddresses -like "*example.com"}

0

Based on the official documentation Filterable properties for the Filter parameter, the cmdlet -Filter should support wildcard character.

I tried to run commands with this cmdlet, then I found username* is allowed, but *domain.com isn't allowed.), it looks like the -RecipientFilter cmdlet(In cloud-based environments, you can't use a wildcard as the first character. For example, 'Sales*' is allowed, but '*Sales' isn't allowed.).

To get the recipient email addresses, you could try to run the following commands:

Get-Recipient | where{($_.Alias -ne $null) -and ($_.PrimarySmtpAddress -like '*@domain.com')}

Or:

Get-Recipient -Filter {(Alias -ne $null) -and (EmailAddresses -like '*@domain.com')}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .