Первый скрипт 2.ps1 :
Код:

$Events = Get-EventLog security -message "*" -before ((get-date -hour 23 -minute 59 -second 59).AddDays(-2)) -after ((get-date -hour 0 -minute 0 -second 0).AddDays(-2)) | ?{$_.eventid -eq 4625}
$Data = New-Object System.Management.Automation.PSObject
$Data | Add-Member NoteProperty Time ($null)
$Data | Add-Member NoteProperty UserName ($null)
$Data | Add-Member NoteProperty Address ($null)
$Data | Add-Member NoteProperty ComputerName ($null)
$Events | %{
$Data.time = $_.TimeGenerated
$message = $_.message.split("`n") | %{$_.trimstart()} | %{$_.trimend()}
$Data.UserName = ($message | ?{$_ -like "Имя учетной записи:*"} | %{$_ -replace "(.+):\s*"})
$Data.Address = ($message | ?{$_ -like "Сетевой адрес источника:*"} | %{$_ -replace "^.+:."})
$Data.ComputerName = ($message | ?{$_ -like "Имя рабочей станции:*"} | %{$_ -replace "^.+:."})
}
$body = [string] $Data
$data
$body
.\Send-Email.ps1 -To "test@test.ru" -Subject "Logs" -Body $body
Его вывод в консоле:
Код:

PS C:\Script> .\2.ps1
Time UserName Address ComputerName
---- -------- ------- ------------
16.06.2013 8:08:18 {-, administrator} 1.1.1.1 SERVER
@{Time=06/16/2013 08:08:18; UserName=System.Object[]; Address=1.1.1.1; ComputerName=SERVER}
Отправка сообщения Send-Email.ps1 :
Код:

param(
[string] $to,
[string] $subject,
[string] $body
)
$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $style + "</style>"
$CredUser = "test@test.ru"
$CredPassword = "pass"
$EmailFrom = "test@test.ru"
$EmailTo = $to
$SMTPServer = "smtp.test.ru"
$message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
$message.Subject = $subject
$message.IsBodyHTML = $true
$message.Body = $body | ConvertTo-Html -Head $style
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Credentials = New-Object System.Net.NetworkCredential($CredUser, $CredPassword);
$smtp.Send($message)
На почту приходит:
*
96
.
Код:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">=
<html xmlns=3D"http://www.w3.org/1999/xhtml"> <head> <style>BODY{font-family:=
Arial; font-size: 10pt;}TABLE{border: 1px solid black; border-collapse:=
collapse;}TH{border: 1px solid black; background: #dddddd; padding: 5px;=
}TD{border: 1px solid black; padding: 5px; }</style> </head><body> <table>=
<colgroup> <col/> </colgroup> <tr><th>*</th></tr> <tr><td>96</td></tr>=
</table> </body></html>
Не могу понять что и где поправить.