此脚本应从事件日志中获取Error
和Warning
个事件,并通过电子邮件发送。目前收到的电子邮件没有正文内容。身体空白的任何想法?
$computers = Get-Content "C:\Source\MorningCheck.txt";
$smtpServer = "mail.mycompany.local"
$smtpFrom = "system@mycompany.com"
$smtpTo = "emailrecipient@mycompany.com"
$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>"
foreach ($computer in $computers) {
$MessageSubject = "Error log for server:" + $Computer
$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$Message.Subject = $messageSubject
$message.IsBodyHTML = $false
$message.Body = Get-EventLog -ComputerName $Computer -LogName System -EntryType "Error","Warning" -After (Get-Date).AddDays(-1) |
Select-Object MachineName, Index, TimeGenerated, EntryType, Source, InstanceID
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
}