Skip to content
Menu

User Locked Out - Unlock the Account

Unlocks the named users only if they are locked out now, then reads each account again to check. An account that is not locked out is left alone.

User locked out - unlock the account is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review User locked out - unlock the account. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows Server 2016+ (domain controller or domain member); runs as SYSTEM
NeedsPowerShell 5.1, administrator rights, ActiveDirectory module (RSAT-AD-PowerShell), rights to unlock AD accounts
Changes thingsChanges what it runs on

What It Does

This script changes one thing: it unlocks the accounts named in AccountName that are locked out now, and then reads each account again to check it is unlocked. It changes nothing else: not the password, not the enabled state, not the group memberships.

Every name is looked up before anything is changed, so one misspelled name stops the run with nothing unlocked. Names can be the sign-in name, DOMAIN\name or the user principal name. An account that is not locked out is left alone and reported as already unlocked, so running it twice is safe. A disabled account that is locked is unlocked but stays disabled, and a warning says so.

Unlocking only lets the user try to sign in again. If the lockouts come back, something is still sending the old password: find it with test-account-lockout-source. If an account is still locked after the unlock, the run ends in an error that says so.

Run it on a domain controller or a member server with the ActiveDirectory module (RSAT). If the module is missing it ends ERROR; on a computer that is not in a domain it ends SKIPPED. It needs rights to unlock AD accounts.

Before You Run It

  • Find out why the account locked first. Run test-account-lockout-source, or the lockout will come back.
  • Use the exact sign-in name, DOMAIN\name or UPN. One name that is not found stops the whole run.
  • Run it with DryRun=true if you want to see which accounts are locked before you unlock them.
  • Tell the user to update any saved passwords on their other devices before they sign in again.

Type and Risk

  • Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
  • Risk: Low. Set DryRun=true, or run it with -WhatIf, to list every change without making any.
  • What it changes: Unlocks the named Active Directory user accounts.
  • Restart: It never restarts the machine.
  • Typical run: Under 15 seconds.
  • Example answer: "Unlocked 1 account(s): jsmith"
  • Tested before listing on a Windows Server 2025 domain controller (VM) with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • AccountName: The users to unlock, separated by commas or semicolons: the sign-in name (jsmith), DOMAIN\jsmith, or the user principal name. Required. (Named AccountName, not UserName: Windows already has an environment variable called USERNAME, which the runtime would read.)

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

clear-account-lockout.ps1 · 817 lines · 41.6 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.