Retrieve a list of locked-out AD accounts.
Search-ADAccount -LockedOut | Select-Object Name, SamAccountNameTo manually unlock a specific user account using their SamAccountName, run the script below by replacing "johndoe" with the actual username.
Unlock-ADAccount -Identity "johndoe"To unlock all locked accounts in the domain, run the script below.
To unlock all locked accounts in the domain, run the script below.To automatically unlock accounts every hour, save the script below as UnlockAccounts.ps1.
Search-ADAccount -LockedOut | Unlock-ADAccountAfter this, create a scheduled task to run it periodically. This schedules the script to run at midnight daily, but you can modify it as needed.
$Action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File C:\Scripts\UnlockAccounts.ps1" $Trigger = New-ScheduledTaskTrigger -Daily -At 12:00AM Register-ScheduledTask -Action $Action -Trigger $Trigger -TaskName "AutoUnlockADAccounts" -Description "Automatically unlocks AD accounts"Unlock a user’s AD account using the script below.
Unlock-ADAccount -Identity usernameYes, run the script below to unlock all locked-out users at once.
Search-ADAccount -LockedOut | Unlock-ADAccountSchedule the unlock script to run periodically via Task Scheduler.