Skip to content

Instantly share code, notes, and snippets.

@PatrickTerlisten
Created February 6, 2022 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatrickTerlisten/33e6c96a0fa890328ed5d9974027d355 to your computer and use it in GitHub Desktop.
Save PatrickTerlisten/33e6c96a0fa890328ed5d9974027d355 to your computer and use it in GitHub Desktop.
E-Mail notification on account lockout
#Get events
$Event = Get-EventLog -LogName Security -InstanceId 4740 -Newest 1
#get some details
$User = $Event.ReplacementStrings[0]
$Computer = $Event.ReplacementStrings[1]
$Domain = $Event.ReplacementStrings[5]
# smtp server
$emailSmtpServer = "mailserver.domain.tld"
# recipient
$emailFrom= "support@mdomain.tld"
$emailTo = "security@domain.tld", "support@mdomain.tld"
$subject = "Benutzerkonto gesperrt:" + $Domain + "\" + $User
$body = "Benutzerkonto: " + $Domain + "\" + $User + "`r`n" + "Workstation: " + $Computer + "`r`n" + "Time: " + $Event.TimeGenerated + "`r`n"
Send-MailMessage -SmtpServer $emailSmtpServer -From $emailFrom -To $emailTo -Subjec $subject -Body $body -BodyAsHtml -Encoding UTF8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment