Powershell Unlock Account – loop

Powershell script to view user account and unlock the account:

[Note: must run as Domain admin to view account and have ActiveDirectory module installed]




Import-Module ActiveDirectory
$val = 0
while ($val -lt 1)
$username = Read-Host -Prompt 'Input the user name'
get-aduser -identity $username -properties passwordlastset, passwordexpired, lockedout, lastlogon, scriptpath

Write-Host -ForegroundColor YELLOW 'Do you need to unlock?'
$confirmation = Read-Host "y/n:"
if ($confirmation -eq 'y') {
unlock-adaccount -identity $username
Write-Host -ForegroundColor YELLOW 'Unlocked :)'
} else {
Write-Host -ForegroundColor YELLOW 'Okay'
Write-Host '------------------------------'
Write-Host '------------------------------'


Leave a Reply

Your email address will not be published. Required fields are marked *