How to Use the Unlock-ADAccount (ActiveDirectory) cmdlet in PowerShell?

An active directory account can be unlocked using PowerShell’s “Unlock-ADAccount” function. In other words, it restores the access of (AD DS) “Active Directory Domain Service” for an account that was locked. The user account gets suspended or locked when they try to add incorrect entries and exceeds the number of allowed entries.

The following post will explain the “Unlock-ADAccount” cmdlet with examples.

How to Use the Cmdlet Unlock-ADAccount (ActiveDirectory)?

The “Unlock-ADAccount” cmdlet is utilized in PowerShell to unlock or restore access to a locked account. It is used by the administrators to unlock the account and let the user log in again to that account.

Example 1: Use the “Unlock-ADAccount” Cmdlet to Unlock an Active Directory Account

Execute the provided command to unlock an account of the active directory:

Unlock-ADAccount -Identity <Username>

Here, first, specify the “Unlock-ADAccount” cmdlet. Then, mention the “-Identity” parameter and assign it the username.

Example 2: Use the “Unlock-ADAccount” Cmdlet to Unlock an Active Directory Account With Confirmation

In order to unlock an active directory account with confirmation simply place the “-Confirm” parameter at the end:

Unlock-AdAccount -Identity <Username> -Confirm

In the above-stated command:

    • Initially, specify the “Unlock-AdAccount” cmdlet.
    • Then, add the “-Identity” parameter having the username assigned to it.
    • After that, specify the “-Confirm” parameter to confirm the unlocking of an account.

Example 3: Use the “Unlock-ADAccount” Cmdlet to Unlock All Active Directory Accounts

Execute the below line of code to unlock all the active directory accounts:

Search-ADAccount -Lockedout | Select-Object Name, SamAccountName

Following the stated code:

    • First, write the “Search-ADAccount” cmdlet along with the “-Lockedout” cmdlet and the pipeline “|”.
    • After that, add the “Select-Object” cmdlet and assign it the stated values separated by a comma.

That was all about the “Unlock-ADAccount” cmdlet in PowerShell.


The “Unlock-ADAccount” cmdlet is utilized to unlock an account or restore access to the suspended account in PowerShell. It can unlock one or more than one account at a time. This cmdlet needs administrator privileges to work properly in PowerShell. The above post has illustrated the “Unlock-ADAccount” cmdlet with the help of various examples.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.