filter logic - exclude multiple

get-aduser -filter {}

I have some users who have ‘xerox’ in their givenname and some others who have ‘xerox’ in their surname. I want to exclude all of them from my search.

the get-aduser filter won’t let me use “notmatch.” do I need to pipe to a where clause or is there a way to get the filter to work?

For this, I would do

Get-ADUser -filter {GivenName -notlike “Xerox” -or Surname -notlike “Xerox”}

If I got it right you will have to change the “-or” to an “-and”. :wink:

You’re correct, that was my bad! Yes should be -and not -or

Get-ADUser -filter {GivenName -notlike "Xerox" -and Surname -notlike "Xerox"}

The only thing I would add to the previous responses is to use wildcards in your search string. The -like and -notlike operators look for an exact match, but it does accept * for a wildcard. I mention this because of your usage of the -notmatch operator. Match looks for patterns (and is capable of regex) where like is not.

thanks everybody. for openers, i’m dumb and I assumed ‘notlike’ wasn’t allowed either, because I think I’ve seen it not work in other filters where ‘notmatch’ wasn’t allowed. didn’t even try it.

{GivenName -notlike “Xerox” -and Surname -notlike “Xerox*”} definitely does what I need, but when i look at it, it really looks like it should mean that ‘Xerox’ needs to appear in Both givenname -And surname for that filter to be true. for grins, what would the syntax be for that filter?