Monday, October 5, 2015

Powershell Quick Script - Get emailed when a specific account is locked

Here's something quick and simple which sends you an email when an AD user account is locked out. The script just runs in a loop, polling ever 30 seconds and then finishes once the account is locked out. This requires a SMTP relay or receive connector on your exchange server to receive email.

$username = 'myuser'
While(Get-AdUser $username).enabled){Start-Sleep -Seconds 30}
Send-MailMessage -To '' -From '' -Subject "Account locked out - $username" `
  -SmtpServer exchangeserver -Body "Your account $username"

No comments: