← script library

Check for Locked Active Directory Accounts

Active DirectoryJanuary 5, 2025

Identifying locked accounts in Active Directory is essential for maintaining security and usability. This PowerShell script allows administrators to check for locked user accounts and helps streamline the process of account management. By running this script, you can quickly identify users who may need assistance regaining access. At ServerEngine, we specialize in providing innovative IT management solutions.

powershell
Import-Module ActiveDirectory

function Get-LockedADAccounts {
    $lockedAccounts = Get-ADUser -Filter { LockedOut -eq $true } -Properties LockedOut | Select-Object Name, SamAccountName, LockedOut
    return $lockedAccounts
}

$lockedUsers = Get-LockedADAccounts
$lockedUsers | Format-Table -AutoSize

$lockedUsers | Export-Csv -Path "C:\Path\To\Your\LockedADAccounts.csv" -NoTypeInformation

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.