Support
 
Phone Live Chat
 
Support
 
US: +1 888 720 9500
 
Intl: +1 925 924 9500
Aus: +1 800 631 268
UK: 0800 028 6590
CN: +86 400 660 8680

Direct Inward Dialing: +1 408 916 9393

 
 
 
 
 

How to search Active Directory

Searching Active Directory (AD) for accounts by their state, such as locked out, disabled, inactive, or expired, lets you find the accounts that need attention without knowing their names. This makes it a routine part of help desk triage, security reviews, and a stale account cleanup before an audit. This guide explains how to search AD for accounts using PowerShell, Active Directory Users and Computers (ADUC), and ManageEngine ADManager Plus.

 
  • PowerShell
  • ADUC
  • ADManager Plus
  • Post-search steps
  • Why ADManager Plus
  • Real-world use cases
  • FAQ
 

How to search for AD accounts using PowerShell

Prerequisites

  • Permissions: You need read access to the accounts you're searching for, which a standard domain account generally has.
  • Tools: Search-ADAccount and Get-ADUser come with the AD module for Windows PowerShell, which is available through RSAT. Import it before searching; on a domain controller (DC), it's present by default:
    Import-Module ActiveDirectory

Search by the name or other attributes

Use Get-ADUser to search for users by their name, email address, department, or other attributes. To retrieve a specific user by their logon name (sAMAccountName), use -Identity:

Get-ADUser -Identity "jbond"

To find users whose Name attribute starts with Bond, use -Filter with a wildcard:

Get-ADUser -Filter "Name -like 'Bond*'" |
    Select-Object Name, SamAccountName

To find objects with names starting with Sales, including users, computers, and groups, use Get-ADObject:

Get-ADObject -Filter "Name -like 'Sales*'" | Select-Object Name, ObjectClass

For a raw LDAP query, -LDAPFilter takes a standard LDAP search filter. For example, to find all users in one department, use the following:

Get-ADUser -LDAPFilter "(department=Sales)" | Select-Object Name, SamAccountName

Search by the account state

Search-ADAccount finds accounts based on their state, such as locked out, disabled, expired, or inactive. For example, to find locked-out accounts, run the following:

Search-ADAccount -LockedOut -UsersOnly |
    Format-Table Name, SamAccountName, LockedOut -AutoSize

The -LockedOut switch returns locked-out accounts within the specified search scope. Pipe the result to Format-Table for a clean list, or add -UsersOnly to exclude computer accounts.

Search for disabled, inactive, and expired accounts

The same cmdlet finds other account states through their switches. -AccountDisabled returns disabled accounts, -AccountExpired returns accounts for which the expiration date has passed, and -AccountInactive with -TimeSpan returns accounts that haven't signed in within a period. This is useful for cleanups:

# Disabled accounts
Search-ADAccount -AccountDisabled -UsersOnly | Select-Object Name, SamAccountName
# Expired accounts
Search-ADAccount -AccountExpired -UsersOnly | Select-Object Name, SamAccountName
# Inactive for more than 90 days
Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 -UsersOnly |
    Select-Object Name, SamAccountName, LastLogonDate

The -TimeSpan value uses the days.hours:minutes:seconds format, so 90.00:00:00 is 90 days. You can also pass it a New-TimeSpan -Days 90 object if you prefer.

Search for accounts with an expired password

To find accounts with an expired password, use the -PasswordExpired switch:

Search-ADAccount -PasswordExpired -UsersOnly |
    Format-Table Name, SamAccountName -AutoSize

Scope any of these searches to a single OU with -SearchBase, giving the OU's distinguished name (DN), which keeps the search fast in a large directory:

Search-ADAccount -LockedOut -SearchBase "OU=Sales,DC=corp,DC=com" -UsersOnly |
    Select-Object Name, SamAccountName

Supported parameters

Parameter or cmdlet Description
Search-ADAccount Finds accounts by their state (locked, disabled, inactive, or expired)
-LockedOut Returns accounts that are currently locked out
-AccountDisabled Returns disabled accounts
-AccountExpired Returns accounts that are past their expiration date
-AccountInactive -TimeSpan Returns accounts with no logon within the given period
-PasswordExpired Returns accounts with an expired password
-UsersOnly or -ComputersOnly Limits the results to user or computer accounts
-SearchBase Scopes the search to a specific OU
Get-ADUser -Filter or Get-ADUser -LDAPFilter Searches by the attribute rather than the account state

Troubleshooting common search errors

  • Search-ADAccount is not recognized: The AD module isn't loaded. Run Import-Module ActiveDirectory; if that fails, install RSAT.
  • Directory object not found or a naming error appears: The -SearchBase DN is mistyped or the OU doesn't exist. Confirm the exact DN (for example, with Get-ADOrganizationalUnit -Filter *).
  • Unexpected search results appear: A state switch may not match as expected (for example, -AccountInactive depends on LastLogonDate, which replicates with a delay, and some conditions like -PasswordExpired are unreliable). Widen the -TimeSpan, verify the search against a known account, or fall back to a Get-ADUser -Filter query, which is more predictable.
  • Computer accounts appear in the results: Search-ADAccount includes computers by default. Add -UsersOnly to limit the search to user accounts.
  • The search is slow on a large domain: Scope it with -SearchBase to the relevant OU rather than searching the whole directory.

Limitations of using PowerShell

  • One condition per command: Combining states (for example, disabled and inactive) or adding attribute columns means scripting beyond a single Search-ADAccount call.
  • Manual exporting and formatting: Getting the results into CSV or another format means piping them to Export-Csv and selecting columns yourself.
  • No scheduling or delivery: Running a search on a cadence and emailing it means building it around Task Scheduler and maintaining the script.
  • Extra setup required for delegation: Providing technicians with a guided interface for approved searches requires building and maintaining wrapper scripts or a custom tool with appropriate access controls.

How to search for AD accounts using ADUC

Prerequisites

  • Permissions: You need read access to the accounts, which a standard domain account has.
  • Tools: You need the ADUC console, which is part of RSAT on Windows 10 and 11 and is present by default on a DC.

Search by the name or attribute with the Find option

  1. Open ADUC by running dsa.msc.
  2. Right-click the domain (or an OU) and select Find.
  3. In the Find Users, Contacts, and Groups dialog box, enter a name, or use the Advanced tab to build a condition on a field such as the email or department, then click Find Now.

Search by the account state

The Find option can’t filter by a locked-out, inactive, or expired status. For account state searches, enable Saved Queries instead: In ADUC, right-click Saved Queries, click New > Query > Define Query, and select a common query such as Disabled accounts or Non expiring passwords, or supply a custom LDAP filter.

Limitations of ADUC

  • The Find option searches by the attribute only; it has no filter for locked, inactive, or expired accounts.
  • Saved Queries cover some states via LDAP but not all (there's no direct locked out query), and exports and bulk actions are also limited.
  • Queries must generally be run manually; the console doesn't provide built-in scheduling for recurring searches.

How to search for AD accounts using ADManager Plus

Native tools often require separate steps to search for accounts, export results, or configure scheduled reports. ADManager Plus simplifies these tasks with a single console for AD, Exchange, and Microsoft 365 management and reporting, with object searches and prebuilt reports that require no scripting.

Find AD objects using the search tool

For an ad hoc lookup by the name or attribute, the AD object search tool finds users, computers, and groups across OUs and domains in one search.

  1. Enter the name of the object you want to find in the Search AD Objects field located in the top-right corner. This opens the Search Users, Groups, Computers & Contacts report, listing the objects that match the name.
  2. For a more targeted search, click Advanced Search and build conditions using the drop-down options.
Finding AD objects using the search tool in ADManager Plus.
Finding AD objects using the search tool in ADManager Plus.

Find accounts with a report

  1. Navigate to Reports > User Reports and open a user report, such as Locked-out Users, Disabled Users, Inactive Users, or Account Expired Users.
  2. Select the domain or OU and click Generate to list the matching accounts.
  3. Click Export As to save the results in CSV, PDF, XLSX, or HTML format, or click Schedule Reports to generate and email the results on a recurring basis.
Finding accounts using the Disabled Users report generated in ADManager Plus.
Finding accounts using the Disabled Users report generated in ADManager Plus.

Post-search steps and considerations

  • Export the results: Save the list of matching accounts to hand to someone or keep as a record, whether as a CSV from a script or an exportable report in CSV, PDF, XLSX, or HTML format.
  • Act on what you find: Searching is often the first step before taking action, such as unlocking, enabling, disabling, or moving accounts. Administrators can select multiple accounts and perform the required action in bulk, where supported.
  • Allow for replication: Account states such as the last logon and lockout can lag across DCs, so confirm them against the right DC before acting on a time-sensitive result.
  • Schedule recurring searches: If you run the same search regularly, such as for locked or inactive accounts, automate it rather than running it by hand each time.

How ADManager Plus helps you find and manage AD accounts

ADManager Plus replaces scripts and one-off searches with a single console for AD, Microsoft 365, and Exchange management and reporting:

Real-world use cases

Use case 1: Find and unlock locked-out accounts

A frequent help desk task is finding which accounts are locked, often to unlock them. Search-ADAccount -LockedOut lists them, and you can pipe the result straight into Unlock-ADAccount.

# List locked accounts
Search-ADAccount -LockedOut -UsersOnly | Select-Object Name, SamAccountName
# Find and unlock them in one line
Search-ADAccount -LockedOut -UsersOnly | Unlock-ADAccount

With ADManager Plus

  1. Navigate to Reports > User Reports > Account Status Reports > Locked-out Users.
  2. Select the locked accounts and click Unlock Users in the report toolbar.

Use case 2: Find accounts that are disabled, expired, or inactive in 1 report

The Search-ADAccount state switches are mutually exclusive, so a single call cannot combine searches for disabled, expired, and inactive accounts. For a combined report, retrieve users with Get-ADUser and use Where-Object with OR logic:

now = Get-Date
$cutoff = $now.AddDays(-90)
Get-ADUser -Filter * -Properties Enabled, AccountExpirationDate, LastLogonDate |
    Where-Object {
        ($_.Enabled -eq $false) -or
        ($null -ne $_.AccountExpirationDate -and $_.AccountExpirationDate -lt $now) -or
        ($null -ne $_.LastLogonDate -and $_.LastLogonDate -lt $cutoff)
    } |
    Select-Object Name, SamAccountName, Enabled, AccountExpirationDate, LastLogonDate

This retrieves all users in the search scope and filters them locally, returning those that are disabled, expired, or have a recorded LastLogonDate older than 90 days. Users without a recorded LastLogonDate are included only if they are disabled or expired.

Note:

LastLogonDate is updated periodically and may lag behind actual activity. Review the results before using them for an account cleanup.

With ADManager Plus

Running a single account status report combines these states without running or merging separate queries.

Use case 3: Find inactive accounts that belong to a specific group

Search-ADAccount doesn’t return group memberships, so you can’t filter its results by memberOf directly. Pipe its output into Get-ADUser to add the memberOf property, then filter the inactive users to include only direct members of the group:

Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 -UsersOnly | Get-ADUser -Properties MemberOf | Where-Object { $_.MemberOf -like "*CN=Finance,*" } | Select-Object Name, SamAccountName

This finds accounts that have been inactive for over 90 days and are members of the named group, which is useful for targeting an AD cleanup at one team or access level.

With ADManager Plus

Combine the Inactive Users report with a group filter to get the same cross section from the console, without any piping.

Use case 4: Find service or privileged accounts

Auditors often ask for a list of service accounts (frequently those set to never expire) or members of privileged groups. For the former, Search-ADAccount with a filter for non-expiring accounts helps; for the latter, resolve a privileged group's membership. A common starting point is finding accounts with a password that never expires:

# Accounts whose password never expires (often service accounts)
Get-ADUser -Filter "PasswordNeverExpires -eq '$true'" -Properties PasswordNeverExpires |
    Select-Object Name, SamAccountName
# Members of a privileged group
Get-ADGroupMember -Identity "Domain Admins" -Recursive |
    Select-Object Name, SamAccountName

With ADManager Plus

  • To find users with passwords set to never expire, navigate to Reports > Password Reports > Users with Password Never Expires.
  • To get a privileged group's membership, navigate to Reports > Group Reports > Group Members.

FAQ

Search-ADAccount finds accounts by their state, such as locked, disabled, inactive, or expired, through dedicated switches and covers both users and computers. Get-ADUser finds users by the attribute using -Filter or -LDAPFilter. Use Search-ADAccount for account state questions and Get-ADUser to search by the name, email, department, or other attributes.

Search-ADAccount includes both user and computer accounts by default since both can be locked, disabled, or inactive. Add -UsersOnly to limit the results to user accounts, or add -ComputersOnly to return only computers.

Use Get-ADUser and read the DistinguishedName property, which is returned by default:

Get-ADUser -Identity "jbond" | Select-Object Name, DistinguishedName

The distinguished name (DN) is the user’s full path in the directory, such as CN=James Bold,OU=Sales,DC=corp,DC=com. In ADUC, click View, enable Advanced Features, open the user’s Properties, and find the DN on the Attribute Editor tab (as distinguishedName) or on the Object tab as the canonical name. ADManager Plus shows the DN as a column in its user reports.

ADManager Plus Trusted By

The one-stop solution to Active Directory Management and Reporting