Saturday, September 28, 2013

Filtering on fields being NULL in Get-ADUser

So you want to fetch Active Directory user objects and filter on a field being null, you might think that this would work to find any users who have nothing in the EmployeeID field:


Get-ADUser -Filter {EmployeeID -like $null} -properties *

However, it does not and neither does this:

Get-ADUser -Filter {EmployeeID -like ""} -properties *

What is the solution? This works:

Get-ADUser -Filter {EmployeeID -notlike "*"} -properties *

In other words, "like nothing" does not work, but "not like anything" does :-)

Cheers!

No comments:

Post a Comment