Author Posts

May 16, 2018 at 9:35 pm

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?

May 16, 2018 at 9:48 pm

For this, I would do

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

May 16, 2018 at 10:22 pm

If I got it right you will have to change the "-or" to an "-and". 😉

May 16, 2018 at 10:27 pm

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

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

May 16, 2018 at 11:02 pm

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.

May 17, 2018 at 3:30 pm

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?