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
lockoutTimeattribute. Help-desk accounts are often delegated this right.
On Windows 11, install the module from an elevated PowerShell session:
Get-WindowsCapability -Name "Rsat.ActiveDirectory*" -Online | Add-WindowsCapability -OnlineOn Windows Server, install it as a feature instead:
Install-WindowsFeature RSAT-AD-PowerShellList every locked-out user
Search-ADAccount has a dedicated switch for locked accounts:
Search-ADAccount -LockedOut -UsersOnly |
Select-Object Name, SamAccountName, LastLogonDate |
Sort-Object NameTo query the PDC emulator directly, look it up and pass it to -Server:
$pdc = (Get-ADDomain).PDCEmulator
Search-ADAccount -LockedOut -UsersOnly -Server $pdcCheck a single user
When a specific person calls the help desk, check their account in detail:
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
Unlock-ADAccount -Identity jsmith -Server $pdcTo unlock everyone who is currently locked out — for example after fixing a misconfigured service — pipe the search results:
Search-ADAccount -LockedOut -UsersOnly -Server $pdc | Unlock-ADAccount -WhatIfFind 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.
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:
TimeCreated User Source
----------- ---- ------
21/10/2026 09:14:02 jsmith LAPTOP-0427
21/10/2026 08:41:55 jsmith LAPTOP-0427If 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
Search-ADAccount -LockedOut -UsersOnlylists everyone who is locked out.Unlock-ADAccountunlocks a user — test bulk operations with-WhatIf.- Event 4740 on the PDC emulator tells you which device caused the lockout.
- Fix the stored credential on that device, or the lockouts will continue.