Forum Discussion
Louaialobaidi
Oct 05, 2023Copper Contributor
powershell script
Hi I need a powershell script that when AD user account is locked out the admin will get a notification email. Thank you
randriksen_
Oct 06, 2023Brass Contributor
As somnio0505 suggests, make a scheduled task triggered on the event
and have it run something like this:
$alert = Get-EventLog -LogName security -instanceid 4740 -Newest 1
$body = $alert.message
#Send email with the report
$smtpServer = "yourmailserver"
$smtpPort = 25
#$smtpUsername = "email address removed for privacy reasons"
#$smtpPassword = "your_email_password"
$to = "sendto"
$from = "sendrom"
$event = $alert.entrytype
$time = $alert.TimeGenerated
$subject = "$event - $time"
$message = New-Object System.Net.Mail.MailMessage $from, $to
$message.Subject = $subject
$message.Body = $body
#$message.IsBodyHtml = $true
$smtp = New-Object System.Net.Mail.SmtpClient $smtpServer, $smtpPort
#$smtp.EnableSsl = $true
#$smtp.Credentials = New-Object System.Net.NetworkCredential $smtpUsername, $smtpPassword
$smtp.Send($message)
You'll have to adapt it to your email server and environment, but it should work as long as you get the right event code
-Ole
somnio0505
Oct 06, 2023Brass Contributor
randriksen I missed that way.
Thank you for completing my insufficient answer.
Thank you for completing my insufficient answer.