PowerShell Genie

Find locked-out users

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Search-ADAccount -LockedOut asks the directory for accounts currently in a locked state, so the selection happens server-side with no client filtering involved.

The script

1PS> Search-ADAccount -LockedOut | Select-Object SamAccountName,Name,ObjectClass

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 SamAccountName Name ObjectClass
    2 -------------- ---- -----------
    3 jdoe Jane Doe user
    Inspect this example’s structure

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

    Search-ADAccount -LockedOut | Select-Object SamAccountName,Name,ObjectClass
    1. Stage 1Search-ADAccount-LockedOut
    2. Stage 2Select-ObjectPositional values or no named parameters

      How it works

      Search-ADAccount -LockedOut asks the directory for accounts currently in a locked state, so the selection happens server-side with no client filtering involved. Select-Object keeps the SAM account name and display name alongside ObjectClass, which distinguishes a user object from a computer.

      Adapting it

      Once the cause is confirmed, chain Unlock-ADAccount onto the same pipeline to clear them in bulk. Adding -UsersOnly to Search-ADAccount removes computer objects when they are cluttering the result.

      Requirements

      ActiveDirectory module; unlocking additionally requires delegated rights.

      If the result is unexpected

      An expected locked account is missing or the result changes between queries.

      Lockout state can change after an unlock and may differ across domain controllers during replication.

      1. Query the intended domain controller and record the observation time alongside the account identity.

      Validate the result

      The reported state agrees with the selected controller at the time of the check.

      Keep the check reliable

      Use time-stamped observations and investigate recurring lockouts separately from current state.

      Primary documentation

      PowerShell objects and pipelines documentation

      Continue
      Genie guideFind locked-out users

      Search-ADAccount -LockedOut asks the directory for accounts currently in a locked state, so the selection happens server-side with no client filtering involved.