title: Email Account Lock Out Notification - Powershell
body: <p>I will like to email the SysAdmin event id 4625 (Account lockout) occurs. </p>
  
  <p>I have the following code, and it works just find. See output attached<a href="https://i.stack.imgur.com/oylZP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oylZP.png" alt="enter image description here"></a>: </p>
  
  <p><strong>Current code:</strong> </p>
  
  <pre><code>$AccountLockOutEvent = Get-EventLog -LogName "Security" -InstanceID 4625 -Newest 1
  $LockedAccount = $($AccountLockOutEvent.ReplacementStrings[0])
  $AccountLockOutEventTime = $AccountLockOutEvent.TimeGenerated
  $AccountLockOutEventMessage = $AccountLockOutEvent.Message
  $messageParameters = @{ 
  Subject = "Account Locked Out: $LockedAccount" 
  Body = "Account $LockedAccount was locked out on $AccountLockOutEventTime..`n`nEvent 
  Details:`n`n$AccountLockOutEventMessage"
  From = "" 
  To = "" 
  SmtpServer = ""
  } 
  Send-MailMessage @messageParameters
  </code></pre>
  
  <p><strong>Question to Powershell gurus</strong></p>
  
  <p>1 - How can I capture the exact reason for lockout instead of %%2313 and other information such as the samaccountname. Instead using Account locked out s-1-0-0 in the subject line, I want to see the Account name there.<br>
  2 - is there a way get the ADuser information so that we can email the user at thesame time informing that that their account was locked out to contact the SysAdmin to unlock the account? </p>