EASYENTRA Blog

News & Updates

Understand LDAP Filter and Syntax

Understand LDAP Filter and Syntax.

Use LDAP filtering to quickly get the information you need from Active Directory or Office 365.

You can use LDAP filtering from PowerShell or even directly in AD Users & Computers. LDAP filters are a super-powerful tool to build reports or do bulk editing.

LDAP filters are processed server-side on the domain controller. You should always filter objects server-side to improve performance.

Tip: If you have many applications doing frequent and complex queries on a huge AD, you should dedicate a domain controller to process these queries.
LDAP Filter Syntax

LDAP filters in their simplest form only match an AD attribute name with a value:

[attribute name]=[attribute value]

Attribute names are the “raw” names you find in the “Attribute Editor” tab in AD Users & Computers.

Attribute names and values are case-insensitive.

For more complex queries, the following four operators should cover most of your needs:

OperatorMeaningSample Expression
&And(&(department=sales)(c=us))
|Or(|(department=sales)(department=marketing))
!Not(!description=external)
*Wildcard(sAMAccountName=EXT*)

As seen in the above examples & (and) and | (or) will perform an and/or on all statements nested in the following parentheses.

E.g. to find all objects where department equals ‘sales’ AND city equals ‘Berlin’ AND country equals ‘Germany’ you would use the following filter:

(&(department=sales)(l=berlin)(c=DE))
You can use AND or OR on any number of statements simply by adding more parentheses.

When you start combining multiple AND and OR operators it quickly leads to higher complexity. Consider the following sample LDAP filter which identifies all users OR groups that have ‘temp’ OR ‘tmp’ in their description attribute:

(&(|(&(objectClass=user)(objectCategory=person))(objectClass=group))(|(description=*temp*)(description=*tmp*)))

In order to construct (or decode) a complex LDAP query you should break it up on several lines like so:

(&
  (|
    (&
      (objectClass=user)
      (objectCategory=person)
    )
    (objectClass=group)
  )
  (|
    (description=*temp*)
    (description=*tmp*)
  )
)

Let’s have a look at the structure:

Line 3 – 6:

Since objectClass=user also returns computer objects, we need to AND with objectCategory=person to only retrieve user objects.

Line 2 – 8:

We limit our search to include only user OR group objects.

Line 9 – 12:

We limit our search to objects that have ‘temp’ OR ‘tmp’ in their description attribute.

Line 1 – 13:

We wrap up our query by AND’ing (users OR groups) with (‘temp’ OR ‘tmp’ in description)

It may take a few tries to get your head around it, but once you have created your first handful of LDAP queries you’ll soon become fluent 😉

PowerShell and LDAP Filter

A lot of the PowerShell get commands, like Get-ADUser, have an LDAPFilter switch (to learn more about the Filter switch read this article).

The LDAPFilter switch takes an LDAP filter query string and allows you to easily list AD objects that match certain criteria.

The following example lists all AD users that are in the marketing department:

Get-ADUser -LDAPFilter '(department=marketing)'

The PowerShell command, Get-ADUser, automatically limits your LDAP search to user objects.

Get-ADGroup and Get-ADComputer have a similar limiting effect on your AD search.

To search for any kind of Active Directory object use Get-ADObject instead.

EasyEntra and LDAP Filter

You can use EasyEntra  to run LDAP queries. 

To execute an LDAP filter, start EasyEntra, select the OU from where you want to base your search (subtree search is default), and type in your search phrase or LDAP query.

Single or multiple search results can be opened and modified.

Furthermore, EasyEntra LDAP queries support friendly names, e.g. “state=idaho” instead of “st=idaho”,
“city=boise” instead of “l=boise”, and “disabled=true” instead of  “userAccountControl:1.2.840.113556.1.4.803:=2”.

Watch a recording with examples of LDAP queries performed in EasyEntra:

For more videos on EasyEntra features, visit our how-to section by clicking here.

Summary

Mastering the basics of LDAP filtering can save you a lot of time and allow you to retrieve information efficiently.

To work even more efficiently, have a look at EasyEntra.

EasyEntra is a stand-alone application that simplifies user administration in hybrid Microsoft 365 and cloud-only environments. It empowers your first-level helpdesk to do senior-level management of Entra ID users, mailboxes, and licenses.

EasyEntra provides one unified, intuitive, and efficient interface, so you no longer have to switch between multiple tools to perform daily management:

Imagine that you no longer have to log in to the Microsoft 365 Admin Center, the Exchange Online Admin Center, or the Azure Portal for daily user management.

You can even synchronize Azure AD Connect directly from EasyEntra.

You can also remove your on-premises Exchange server to avoid future zero-day exploits.

Start your zero-risk 30-day trial now. With just a few minutes to install, we guarantee you’ll be saving hours of work before the end of the week with EasyEntra.

Free 30-minute demo

try 30 days for free

GET EASYENTRA NEWS

Opt out at any time

“One of the best products I've used.”
Gary Shurland
Chief Information Officer, Mirick, United States
“This tool has been invaluable in streamlining our IT processes.”
Tyson Mckay
Chief Information Officer, Southwest Network, United States
“This product has been a miracle for our Help Desk. EasyEntra has completely transformed how we handle Microsoft 365 administration.”
Doug Sanders
Manager of Technical Customer Support, Junior Achievement USA, United States
“Your product is such a time saver. I love it!”
Scott Fehr
IT Infrastructure, MEC Aerial Work Platforms, United States
“It's a good product and saves us lots of time for these ongoing quick admin tasks.” 
Chris McFerran
Managing Director, CTech IT Solutions Ltd, United Kingdom
“EasyEntra has significantly streamlined our workflow, simplifying everything. It feels almost like a revolution.”
Johan Sadelius
IT-chef, Arjeplog Kommun, Sweden
I greatly appreciate your assistance and willingness to enhance the already outstanding product.”
Michael I. Wilson
Executive Director of Information Technology, Archdiocese Of Washington, United States
“It's great not having to switch back and forth between the O365 admin center and the Teams admin center to assign groups. I am sold!”
Thomas Madden
Director Information Technology, AutoPayPlus, United States
“I would highly recommend organizations use the solution as it greatly simplifies various tasks.”
S. Roger Singh
Chief Technology Officer, Prasad & Company LLP, Canada
“EasyEntra is time-saving. Love the copy/paste for user/computer groups and the copy to new user.”
Damian Nita
Associate Network Administrator, Shenandoah Valley Westminster-Canterbury, United States
“EasyEntra has transformed our daily IT operations by simplifying user management, reducing errors, and enhancing overall efficiency.”
Henrik Nefling
IT- and Digitalization Manager, Animal Protection Denmark, Denmark