Get-ADUser -Filter Example

Get-ADUser Filter

The PowerShell command Get-ADUser is part of the Active Directory PowerShell module. Go to this article if you want to know how to install it.

You should use the Filter switch to search effectively for users in your Active Directory. Don’t extract all users and then search the result set.

Use Get-ADUser -Filter to search directly for improved performance.

Understand the Get-ADUser Filter Parameter

With the many various filtering options available (LDAP filtering, oData v3.0 filtering, etc.), the filter switch often causes confusion.

The filter switch used in the Get-ADUser and Get-ADGroup commands uses the PowerShell expression language in the query string.

This is different than, e.g., when using the Get-AzureADUser command (which uses oData v3.0 filtering)!

To understand the (superior) LDAPFilter switch, read this article.

The following operators should cover most of your needs:

OperatorMeaningSample expression
-eqEqual toDisplayName -eq ‘Jonas Watt Boolsen’
-neNot equal toCountry -ne ‘DK’
-gtGreater thanBadLogonCount -gt ‘0’
-geGreater than or equalModified -ge ’06-04-2021 12:00:00′
-ltLess thanLastLogonTimeStamp -lt ’01-01-2021′
-leLess than or equalCreated -le ’01-01-2020′
-likeWildcard searchMail -like ‘*@easy365manager.com’
-notlikeWildcard search with negationDepartment -notlike ‘*’
-andAndCountry -eq ‘DK’ -and Department -eq ‘Sales’
-orOrCountry -eq ‘DK’ -or -Country -eq ‘DE’

Please notice the following in the above examples:

  • Enclose the compared value(s) in apostrophes
  • Use -like ‘*’ and -notlike ‘*’ to find empty or non-empty values 
  • Filter “cryptic” date/time formats directly with a DateTime variable (like e.g. the LastLogonTimeStamp attribute which uses the FileTime format)

Below you have some code snippets that should point you in the right direction on how to structure your filters for your Get-ADUser search queries:

Get-ADUser -Filter 'DisplayName -eq "Jonas Watt Boolsen"'
Get-ADUser -Filter 'Country -ne "DK"'
Get-ADUser -Filter 'BadLogonCount -gt "0"'
Get-ADUser -Filter 'Modified -ge "06-04-2021 12:00:00"'
$Date = (Get-Date).AddDays(-60)
Get-ADUser -Filter 'LastLogonTimeStamp -lt $Date'
Get-ADUser -Filter 'Created -le "01-01-2020"'
Get-ADUser -Filter 'Mail -like "*@easy365manager.com"'
Get-ADUser -Filter 'Department -notlike "*"'
Get-ADUser -Filter 'Country -eq "DK" -and Department -eq "Sales"'
Get-ADUser -Filter 'Country -eq "DK" -or -Country -eq "DE"'

Why Struggle With PowerShell in the First Place?

If you’re still using Active Directory Users & Computers (ADUC) for day-to-day management, it’s time for an upgrade. EasyEntra is a free, modernized replacement that takes everything you wish ADUC could do – and makes it a reality.

Here’s how EasyEntra supercharges searching and filtering:

  • Instant search results as you type
    No more waiting or hitting “Enter.” EasyEntra returns live search results instantly, even in large environments.

  • 🔍 Full support for LDAP queries
    Power users can leverage complex LDAP filters, and EasyEntra evaluates them in real time as you type – perfect for testing queries quickly.

  • 📝 Relaxed typed queries for everyday use
    No need to memorize LDAP syntax for common tasks. Simply type queries like:

    • disabled=true to find disabled accounts

    • lockedout=true to locate locked-out users

    • lastlogon<2025-01-01 to filter by operating system

It’s intuitive and flexible, ideal for both junior IT staff and seasoned administrators.

On top of this, you can easily customize the properties included in the search result and export all data to a .csv file. No more escalation to senior IT when a quick insight into AD is needed.

And the best part? EasyEntra is completely free – forever – for pure AD management and for hybrid and cloud-only environments with up to 25 licensed users.

EasyEntra installs in under a minute, requires no servers or service accounts, and works side by side with your existing tools.

Turbo-charge your first-line support now by downloading the 30-day trial.

“One of the best products I’ve used.” – CIO, Mirick Law, United States

“We really love working with EasyEntra.” – Head of IT, IKN GmbH, Germany

“It feels almost like a revolution.” – IT Manager, Arjeplog Kommun, Sweden

EasyEntra mimics the layout of AD Users & Computers to ensure easy adoption within your helpdesk. But it does so much more:

  • Management of cloud group membership.
  • Management of Microsoft 365 licenses.
  • Management of all Exchange Online mailbox settings.
  • Management of cloud-only objects.
  • Easy automation of user onboarding/offboarding in an easy-to-follow script-less procedure.
  • Single-click synchronization of Azure AD Connect.
  • Copy/paste group membership and mailbox permissions.
  • Uses standard OAuth2 authentication with full support for MFA, PIM, and FIDO2 access keys.
  • 10-second installation and 20-second configuration.
  • Installs on Windows 10/11 or Windows Server 2019 or later.
  • No server/service/service account is needed.
  • No trust in third-party cloud applications is needed.
  • Extensive documentation for easy Helpdesk handover.

With EasyEntra, you can literally cut 50-75% of the cost of Microsoft 365 management in a few minutes.

Sounds too good to be true? Download the 30-day trial and experience EasyEntra firsthand.