header image

Filtering on if an AD property exists

Posted by: | January 26, 2015 Comments Off on Filtering on if an AD property exists |

There are times when you want to filter the results based on whether a user has an AD property set.  You could do this:

Get-ADUser -Filter * -Properties Title | Where Title  | select Name, Title


However, that involves pulling back all of the users and then filtering. Not very efficient especially across the network in a big domain.

A better solution would be to use an LDAP filter

Get-ADUser -LDAPFilter "(Title=*)" -Properties Title  | select Name, Title


Get-ADUser does the checking to see if the user has a title set so only those objects with that property are retrieved. If you want to see the value of the property you need to include it by using the –Properties parameter.

under: PowerShell and Active Directory

Comments are closed.