Admin Login

Find Locked Out Active Directory Accounts and Unlock Them with PowerShell

List locked out users with Search-ADAccount, unlock one or many with Unlock-ADAccount, and see lockout time and bad logon count.

Finding locked out accounts in Active Directory and unlocking them does not require opening users one by one in Active Directory Users and Computers. The PowerShell ActiveDirectory module does it in a few commands.

The commands run on a computer with RSAT installed or on a domain controller. To load the module:

Import-Module ActiveDirectory

List locked out users

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

To see when the lockout happened and how many bad attempts were made:

Search-ADAccount -LockedOut -UsersOnly |
  Get-ADUser -Properties AccountLockoutTime, BadLogonCount |
  Select-Object SamAccountName, AccountLockoutTime, BadLogonCount

Note: lockout information travels between domain controllers by replication. The most current information is on the domain controller holding the PDC emulator role, which learns about lockouts first. If results look inconsistent, point the query there:

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

Unlock a single user

Unlock-ADAccount -Identity ahmet.yilmaz

To confirm the lock is gone:

Get-ADUser ahmet.yilmaz -Properties LockedOut | Select-Object SamAccountName, LockedOut

Unlocking does not change the password. If the user knows their password, unlocking is all that is needed.

Unlock in bulk

To unlock every locked out user in an OU:

Search-ADAccount -LockedOut -UsersOnly -SearchBase "OU=Staff,DC=company,DC=local" |
  Unlock-ADAccount -WhatIf

-WhatIf first lists the accounts that would be unlocked; after checking, run it without -WhatIf.

Caution: do not make bulk unlocking a habit. Many accounts locking at the same time can be a sign of a password spraying attack. Before unlocking, look at events 4740 and 4771 on the domain controllers.

If an account keeps locking

Unlocking does not fix the cause; the account locks again a few minutes later. To find the source, see finding the lockout source with event 4740. A script that does the same is on the free tools page.

Leaving unlock to the user

These commands speed up IT, but the request still reaches the help desk. With a self-service portal the user verifies with a code sent to their registered phone and unlocks the account themselves; the password does not change. In PRESS this flow is separate from password reset, and every operation is written to the audit log.

Try the unlock flow in the live demo

Evaluate PRESS in your own environment.

Through the live demo you can explore the user portal and the admin panel directly.