How to use where-object match one of multiple values from an array. You do not have to use an array. You can just type all the values in a string separated with | between each word(s). Note : Do not have any spaces before or after the pipe character, it is an exact match.

1
2
3
$email = @('test.com', 'foo.com', 'bar.com')
get-mailbox | Where-Object {
$_.ForwardingSmtpAddress -match ($email -join '|')}
Categories: Powershell