Skip to content

Instantly share code, notes, and snippets.

@PatrickTerlisten
Created February 6, 2022 11:10
Show Gist options
  • Save PatrickTerlisten/12b59ff6523f30d59f061906b8e4e8a1 to your computer and use it in GitHub Desktop.
Save PatrickTerlisten/12b59ff6523f30d59f061906b8e4e8a1 to your computer and use it in GitHub Desktop.
E-Mail notification for new AD user
#Get events
$Event = Get-EventLog -LogName Security -InstanceId 4720 -Newest 1
#get some details
$User = $Event.ReplacementStrings[0]
$Creator = $Event.ReplacementStrings[4]
$Domain = $Event.ReplacementStrings[5]
# smtp server
$emailSmtpServer = "mailserver.domain.tld"
# recipient
$emailFrom= "[email protected]"
$emailTo = "[email protected]", "[email protected]"
$subject = "Neuer Benutzer im AD: " + $Domain + "\" + $User
$body = "Neuer Benutzer: " + $Domain + "\" + $User + "`r`n" + "Antragsteller: " + $Creator + "`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