Account lockouts are one of the most common tickets an IT support team handles. Unlocking the account is easy; finding out why it keeps locking is where most of the time goes. This guide shows you how to do both from PowerShell.

What you need

  • A domain-joined Windows computer or server.
  • The Active Directory module for Windows PowerShell, part of the Remote Server Administration Tools (RSAT).
  • An account with permission to read user objects and, for unlocking, to write the lockoutTime attribute. Help-desk accounts are often delegated this right.

On Windows 11, install the module from an elevated PowerShell session:

PowerShell
Get-WindowsCapability -Name "Rsat.ActiveDirectory*" -Online | Add-WindowsCapability -Online

On Windows Server, install it as a feature instead:

PowerShell
Install-WindowsFeature RSAT-AD-PowerShell

List every locked-out user

Search-ADAccount has a dedicated switch for locked accounts:

PowerShell
Search-ADAccount -LockedOut -UsersOnly |
    Select-Object Name, SamAccountName, LastLogonDate |
    Sort-Object Name

To query the PDC emulator directly, look it up and pass it to -Server:

PowerShell
$pdc = (Get-ADDomain).PDCEmulator
Search-ADAccount -LockedOut -UsersOnly -Server $pdc

Check a single user

When a specific person calls the help desk, check their account in detail:

PowerShell
Get-ADUser -Identity jsmith -Server $pdc -Properties LockedOut, lockoutTime, BadLogonCount, LastBadPasswordAttempt |
    Select-Object Name, LockedOut, BadLogonCount, LastBadPasswordAttempt,
        @{ Name = 'LockedAt'; Expression = { [datetime]::FromFileTime($_.lockoutTime) } }

BadLogonCount and LastBadPasswordAttempt are not replicated between domain controllers, so each DC reports only the failures it processed itself. Querying the PDC emulator gives the most useful picture.

Unlock the account

PowerShell
Unlock-ADAccount -Identity jsmith -Server $pdc

To unlock everyone who is currently locked out — for example after fixing a misconfigured service — pipe the search results:

PowerShell
Search-ADAccount -LockedOut -UsersOnly -Server $pdc | Unlock-ADAccount -WhatIf

Find the source of repeated lockouts

When an account is locked out, the domain controller writes event ID 4740 to its Security log. The PDC emulator records every lockout in the domain, and the event includes the Caller Computer Name — the device that sent the bad password.

PowerShell
Get-WinEvent -ComputerName $pdc -FilterHashtable @{ LogName = 'Security'; Id = 4740 } -MaxEvents 50 |
    Select-Object TimeCreated,
        @{ Name = 'User';   Expression = { $_.Properties[0].Value } },
        @{ Name = 'Source'; Expression = { $_.Properties[1].Value } }

Example output:

Output
TimeCreated          User    Source
-----------          ----    ------
21/10/2026 09:14:02  jsmith  LAPTOP-0427
21/10/2026 08:41:55  jsmith  LAPTOP-0427

If the query returns no events, confirm that Audit User Account Management is enabled for domain controllers under Advanced Audit Policy Configuration → Account Management.

Common causes once you know the device

Saved credentials

Open Credential Manager on the source device and remove old entries for file shares, Remote Desktop or Microsoft 365.

Mapped drives and scheduled tasks

Drives mapped with "Connect using different credentials" and scheduled tasks that run as the user keep the old password until they are updated.

Services running as a user account

Check services.msc for services whose Log On As is the user. Use a dedicated service account or a group Managed Service Account instead.

Mobile devices

Phones still configured with the old password retry constantly through Exchange ActiveSync. The source will often be your mail server or a proxy rather than the phone itself.

Disconnected remote sessions

A disconnected RDP session on another server can keep using cached credentials. Sign the user out of old sessions with quser and logoff.

Summary

  1. Search-ADAccount -LockedOut -UsersOnly lists everyone who is locked out.
  2. Unlock-ADAccount unlocks a user — test bulk operations with -WhatIf.
  3. Event 4740 on the PDC emulator tells you which device caused the lockout.
  4. Fix the stored credential on that device, or the lockouts will continue.