Exchange Powershell "NotMatch" doesn't seem to work

I'm trying to creat a listing of Exchange users that do NOT have a certain string in their list of email addresses. I am trying the one liner below and it does not work, I get back a listing of every user:

Get-MailboxServer | Get-Mailbox | where {$_.EmailAddresses -NotMatch "jrnl"} | Select EmailAddresses

However if I run this command instead, it filters out just the users who's email list DOES include the string:

Get-MailboxServer | Get-Mailbox | where {$_.EmailAddresses -Match "jrnl"} | Select EmailAddresses

So I know the variables are all getting passed in and read correctly, I just can't figure out why the "Not" form of "Match" isn't working. (I've also tried -NotLike and -NotContains with the same results)

Any assistance would be greatly appreciated.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

From the PowerShell help:
When the input to an operator is a scalar value, comparison operators
    return a Boolean value. When the input is a collection of values, the
    comparison operators return any matching values. If there are no matches
    in a collection, comparison operators do not return anything.

    The exceptions are the containment operators (-Contains, -NotContains),
    the In operators (-In, -NotIn), and the type operators (-Is, -IsNot),
    which always return a Boolean value.

When you're testing the condition {$_.EmailAddresses -NotMatch "jrnl"}  (or using -Match), that isn't returning a boolean, but the addresses instead.  So you would get all the addresses (an array) that don't have "jrnl" in them.  An array evaluates to TRUE and so Where-Object passes along the object.

You can either look at each value in $_.EmailAddresses individually, so that you're looking at a string (a scalar value), or in this case you can kind of twist the logic a bit, looking for a match from the collection but then filtering out those that have a match.
Get-MailboxServer | Get-Mailbox | where { !($_.EmailAddresses -Match "jrnl") } | Select EmailAddresses

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BWK-AdminAuthor Commented:
That worked perfectly, thank you very much!
BWK-AdminAuthor Commented:
I was able to get the results I needed, by outputting the entire list of mailbox addresses to a text file, then using FIND from a command line to filter out mailboxes without the matching string using /V.

Now I run this code, and get the exact same results with less effort, so I know this works 100%.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.