AD 锁定电子邮件警报脚本间歇性运行

AD 锁定电子邮件警报脚本间歇性运行

因此,我们已经使用这个 PS 脚本一段时间了,在迁移域控制器之前,它一直运行良好。新的域控制器运行的是核心 Microsoft Windows Server 2019 Datacenter。我们有 2 个域控制器,并且都在任务计划程序中启用了。但由于某种原因,该脚本工作不连贯。有时它会发出警报,有时则不会。我不知道问题到底是什么。

这是我的脚本:


#################################################################

#Declare variables to be used for the Email
$MailSubject= “User Account locked out”
$MailFrom=”[email protected]
$MailTo=”[email protected]

#Gets the Event Log that contains the most recent lockout event
$Event = Get-EventLog -LogName Security -InstanceId 4740 -Newest 1

#Creates a variable which contains the contents of the lockout event log. This is used for the actual message in the email
$MailBody= $Event.Message + “`r`n`t” + $Event.TimeGenerated

#Creates an SMTP Object and assigns an SMTP Address
$SmtpClient = New-Object system.net.mail.smtpClient
$SmtpClient.host = “our-adconnect.ourdomain.local”

#Creates a new Mail Message Object. This is the object needed for the addressing email, subject, body, etc
$MailMessage = New-Object system.net.mail.mailmessage
$MailMessage.from = $MailFrom
$MailMessage.To.add($MailTo)
$MailMessage.IsBodyHtml = 0
$MailMessage.Subject = $MailSubject
$MailMessage.Body = $MailBody

#Actually Sends the Message
$SmtpClient.Send($MailMessage)

答案1

尝试在 WAC 中设置它,但没有成功。从另一台服务器导出一个任务,然后使用 schtasks 将其导入核心服务器。成功了。

相关内容