Search-ADAccount
Use Search-ADAccount to find accounts matching a built-in condition such as locked out, disabled, expired or inactive.
Documentation: Microsoft Learn — Search-ADAccount
Syntax
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>]- Stage 1Search-ADAccount
-LockedOut -AccountDisabled -AccountExpired -PasswordExpired -PasswordNeverExpires -AccountInactive -TimeSpan -DateTime -UsersOnly -ComputersOnly -SearchBase
Try it
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.
Follow the objects
Run the command to inspect each stage.
Examples
Select Name, SamAccountName
Show reference output
Sample output · fictional data, shaped like the real thing
Name SamAccountName ---------- -------------- Jane Smith jsmith
Select 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
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
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.
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