sea707, я создаю в планировщике контроллера задание, например, на создание пользователя (User Account Created), триггер — по событию 4720, журнал Security, действие — запуск скрипта Powershell:
Код:
$Subject = "A user account was created"
$Theme = "A user account was created:"
$Server = "smtp.office365.com"
$From = "test@firma.ru"
$To = "admin@firma.ru"
$encoding = [System.Text.Encoding]::UTF8
$secpasswd = ConvertTo-SecureString "Str0Ng_P@ssw0rD" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($From, $secpasswd)
$Body = Get-WinEvent -maxevents 1 -FilterHashtable @{LogName = "Security";ID = 4720;StartTime = (Get-Date).AddSeconds(-60)} | Select TimeCreated,`
@{n = "Account name";e = {([xml]$_.ToXml()).Event.EventData.Data | ?{$_.Name -eq "TargetUserName"} | %{$_.'#text'}}}, `
@{n="Display name";e={([xml]$_.ToXml()).Event.EventData.Data | ? {$_.Name -eq "DisplayName"}| %{$_.'#text'}}}, `
@{n="UPN name";e={([xml]$_.ToXml()).Event.EventData.Data | ? {$_.Name -eq "UserPrincipalName"}| %{$_.'#text'}}}, `
@{n="Created by";e={([xml]$_.ToXml()).Event.EventData.Data | ? {$_.Name -eq "SubjectUserName"}| %{$_.'#text'}}}, `
@{n="DC";e={([xml]$_.ToXml()).Event.System.Computer}}
$body = $body -replace "@{" -replace "}" -replace "=", ": " -replace ";","`n" -replace "TimeCreated","Time Created" -replace "^","`n"
$BodyM = $Body
Send-MailMessage -From $From -To $To -SmtpServer $server -Body "$Theme `n$BodyM" -Subject $Subject -Encoding $encoding -Port "587" -Credential $mycreds -UseSsl
У нас на работе почтовик на Office365, но я думаю, что не составит труда подставить свои данные.