PowerShell Genie

Search-ADAccount

Use Search-ADAccount to find accounts matching a built-in condition such as locked out, disabled, expired or inactive.

Command 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — Search-ADAccount

Syntax

1PS> Search-ADAccount [-LockedOut] [-AccountDisabled] [-AccountExpired] [-PasswordExpired] [-PasswordNeverExpires] [-AccountInactive] [-TimeSpan <TimeSpan>] [-DateTime <DateTime>] [-UsersOnly] [-ComputersOnly] [-SearchBase <String>] [<CommonParameters>]
See the command anatomy

Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

Search-ADAccount [-LockedOut] [-AccountDisabled] [-AccountExpired] [-PasswordExpired] [-PasswordNeverExpires] [-AccountInactive] [-TimeSpan <TimeSpan>] [-DateTime <DateTime>] [-UsersOnly] [-ComputersOnly] [-SearchBase <String>] [<CommonParameters>]
  1. Stage 1Search-ADAccount-LockedOut -AccountDisabled -AccountExpired -PasswordExpired -PasswordNeverExpires -AccountInactive -TimeSpan -DateTime -UsersOnly -ComputersOnly -SearchBase

    Try it

    Windows PowerShell

    PowerShell example · browser support is limited.

    Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.

    Interactive simulation · fictional data

    Examples

    Select Name, SamAccountName

    1PS> Search-ADAccount -LockedOut -UsersOnly | Select-Object Name, SamAccountName
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Name        SamAccountName
    ----------  --------------
    Jane Smith  jsmith

    Select Name, LastLogonDate

    1PS> Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 -UsersOnly | Select-Object Name, LastLogonDate
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Name        LastLogonDate
    ----------  --------------------
    Jane Smith  9/10/2026 8:42:14 AM
    Alex Jones  9/10/2026 9:03:51 AM

    Search-ADAccount -PasswordNeverExpires

    1PS> Search-ADAccount -PasswordNeverExpires -UsersOnly | Measure-Object
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Count    : 2
    Average  :
    Sum      :
    Maximum  :
    Minimum  :
    Property :

    Parameters

    Parameter definitions:

    • -LockedOut
    • -AccountDisabled
    • -AccountExpired
    • -PasswordExpired
    • -PasswordNeverExpires
    • -AccountInactive
    • -TimeSpan
    • -DateTime
    • -UsersOnly
    • -ComputersOnly
    • -SearchBase

    Search-ADAccount on Microsoft Learn

    Practical use and troubleshooting

    Practical scenario: Use Search-ADAccount when you need to find accounts matching a built-in condition such as locked out, disabled, expired or inactive. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.

    Common error and fix: An unexpected account set can come from querying the wrong domain or condition. Specify the intended directory scope and inspect the returned state before using the list for changes. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.

    See also: Unlock-ADAccount. Unlock-ADAccount clears an account lockout; Search-ADAccount finds accounts matching supported conditions. Discovery does not change the state of the accounts returned. Read the linked command before substituting it; similar names do not imply identical inputs or output.

    Search-ADAccount reference on Microsoft Learn

    Recap

    Search-ADAccount Use Search-ADAccount to find accounts matching a built-in condition such as locked out, disabled, expired or inactive.

    Next: Enable-ADAccount
    Genie guideSearch-ADAccount

    Use Search-ADAccount to find accounts matching a built-in condition such as locked out, disabled, expired or inactive. The console below is pre-loaded — run it, then change a value and run it again.