Kieran Dunn
Kieran Dunn

Reputation: 13

Selecting AD Users with listed fields empty

I would like to list all of the users in my domain without specific fields being filled in, In this case, Telephone Number and Title. I have attempted this through Get-ADUser

Get-ADUser -Filter {Title -NotLike "*" -or Telephone-Number -NotLike "*"} -properties name, emailaddress, office, enabled, telephone-number | select name, emailaddress, office, enabled, telephone number | Export-csv -path c:\temp\cwadtwoexport.csv

and

Get-ADUser -Filter {Title -NotLike "*" -or Telephone-Number -NotLike "*"} -properties name, emailaddress, office, enabled | select name, emailaddress, office, enabled | Export-csv -path c:\temp\cwadexport.csv

The second one worked, However it appears to have exported all users in the directory, Regardless of having fields empty or not.

Any advice would be helpful, I am most likely just missing something completely basic.

Thanks in advance

Upvotes: 1

Views: 635

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200193

The simplest way would probably be an LDAP filter:

Get-ADUser -LDAPFilter '(|(!(title=*))(!(telephoneNumber=*)))'

(!(attribute=*)) means "where the given attribute does not have any value" (i.e. is null).
(|...) combines the nested expressions with a logical OR operation.

Upvotes: 1

Related Questions