Unlock AD Account with PowerShell

Updated

how to unlock ad accounts with powershell

The Unlock-ADAccount cmdlet is the fastest way to unlock Active Directory user accounts with PowerShell. In this guide, I’ll show you how to unlock a single account, unlock all locked accounts at once, and verify the lockout status. I’ll also cover an alternative method using the AD Pro Toolkit.

How to Unlock AD Account with PowerShell

Step 1. Open PowerShell and run the command below. Replace username with the account’s logon name.

Unlock-ADAccount -Identity username

Step 2. To check the lockout status of an account, use this command.

Get-ADUser robert.allen -Properties * | Select-Object LockedOut
powershell get locked users

Example 2. Unlock AD Account with Confirmation

This command is the same as the previous example but it adds a confirmation for each account to unlock.

<span style="font-weight: 400;">Unlock-AdAccount -identity alice.mills -Confirm</span>

This will pop up a message to confirm the action.

unlock ad account with powershell

Tip: If you have repeated accounts locked out you should investigate why before unlocking them all. You can check out this how to guide for troubleshooting account lockouts and tracking down the source of lockout events.

Unlock All AD User Accounts with PowerShell

I don’t recommend this but you can find all locked users and unlock them with the command below. If a large number of accounts are locked out that should raise some concerns. You should investigate and look at the logs to ensure nothing suspicious is going on in your network.

Search-ADAccount -Lockedout | select-object Name, SamAccountName

In this example, I have locked three accounts, I’ll use the Search-ADAccount command to list all the locked accounts.

find all locked users

To unlock all the accounts at once I just add | Unlock-AddAccount to the end of the search command, example screenshot below.

unlock all users

I’ll run Search-AdAccount -lockout again to confirm all the accounts were unlocked.

verify accounts are unlocked

You can see above that no accounts are listed.

Again I would be cautious about unlocking all the user accounts at once. Accounts are locked out for a reason (multiple bad password attempts) so unless you know exactly what’s going on be careful with this one.

You can also add the -confirm to this example to confirm each unlock.

confirm account lockout

Try these commands out and let me know how they work by leaving a comment below.

PowerShell Alternative: AD Pro Toolkit

The AD Pro Toolkit includes a password reset tool that makes it easy to find locked users, reset passwords and unlock accounts.

With a single click you can get all locked users.

Password reset tool listing every locked account from one scan