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')}
Best Answer
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:Results in:
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 theWhere-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"}