Hello all
Was wondering if anyone can help me out. Looking to setup a second email notification on a script to a different email address The second message is getting sent to the affected user. the first message gets sent to our helpdesk ticketing software.
Here is the code
import-module activedirectory
$Event = Get-EventLog -LogName Security -InstanceId 4740 -Newest 1
$Usr = $Event.Message -split [char]13
# [#] is the line number in the output
$Usr = $Usr[10]
# (#) is the substring of that line
$Usr = $Usr.substring(17)
$Usr2 = Get-ADUser $Usr | Select-Object -ExpandProperty name
$OU = Get-ADUser $Usr -Properties distinguishedname,cn | select @{n='AD OU: ';e={$_.distinguishedname -replace '^.+?,(CN|OU.+)','$1'}}
$Email = Get-ADUser $Usr -Properties mail
$TelephoneNumber = Get-ADUser $Usr -Properties telephoneNumber | Select-Object -ExpandProperty telephoneNumber
#send lockout notification to helpdesk ticketing system.
$MailBody= $Event.Message + "`r`n`t" + $Event.TimeGenerated + "`r`n`t" + $OU + "`r`n`t" + $Email.mail + "`r`n`t" + "Direct: $TelephoneNumber" + "`r`n`t" + "`r`n`t" + "*ATTENTION* Do not automatically unlock the user's account, please follow up with them first"
$MailSubject= "User Account Locked Out: " + $Usr2
$SmtpClient = New-Object system.net.mail.smtpClient
$SmtpClient.host = "newport.wesley.int"
$MailMessage = New-Object system.net.mail.mailmessage
$MailMessage.from = "AcctLockNotify@wesley.edu"
$MailMessage.To.add("helpdesk@wesley.edu")
$MailMessage.IsBodyHtml = 0
$MailMessage.Subject = $MailSubject
$MailMessage.Body = $MailBody
$SmtpClient.Send($MailMessage)
#send message to the locked out users
$SmtpClient = New-Object system.net.mail.smtpClient
$SmtpClient.host = "newport.wesley.int"
$MailMessage.from = "AcctLockNotify@wesley.edu"
$MailMessage.To.add("$email.mail")
$MailMessage.Body = "$Usr2 Your wesley logon has been locked out. Please contact the IT DepT (302)736-4199, or come to the IT Dept. office to have your Wesley Account unlocked."
$SmtpClient.Send($MailMessage)
I don’t know if I’m missing something.
Thanks.
Brent.