开发者

how to email system & application eventlogs in the same email

This code is to send me errors of eventlogs in an email everyday, but how do I put application & system logs together in one email? Thanks.

$emailFrom = "admin@company.com"
$emailTo = "user@company.com"
$subject = "Daily Eventlog Errors"
$emailbody = get-eventlog -logname application -entrytype Error, Warning -after (get-date).addHours(-24) -computer (get-conte开发者_开发百科nt c:\ServerList.txt) |
select MachineName, timewritten, source, message |format-table -auto  | out-string
$message = New-Object Net.Mail.MailMessage($emailFrom, $emailTo, $subject, $emailbody)
$smtpServer = "companyemail.exchangemail.com"
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)


$emailbody = get-eventlog -logname application -entrytype Error, Warning -after (get-date).addHours(-24) -computer (get-content c:\ServerList.txt) |
select MachineName, timewritten, source, message |format-table -auto  | out-string

$emailbody = $emailbody + " " + get-eventlog -logname system -entrytype Error, Warning -after (get-date).addHours(-24) -computer (get-content c:\ServerList.txt) |
select MachineName, timewritten, source, message |format-table -auto  | out-string


its not the newest post, but its the one I got up when I searched for a script to do this.

I took the liberty to add my own touch to it, and felt I should post it here:

$emailFrom = "admin@company.com"
$emailTo = "user@company.com"
$subject = "Daily Eventlog Errors"

$emailbodyAPP = get-eventlog -logname application -entrytype Error, Warning -after (get-date).addHours(-24) -computer (get-content c:\ServerList.txt) | 
select MachineName, timewritten, source, message |format-table -auto  | out-string

$emailbodySRV = get-eventlog -logname system -entrytype Error, Warning -after (get-date).addHours(-24) -computer (get-content c:\ServerList.txt) | 
select MachineName, timewritten, source, message |format-table -auto  | out-string

$emailbody = $emailbodyAPP + $emailbodySRV

$message = New-Object Net.Mail.MailMessage($emailFrom, $emailTo, $subject, $emailbody)
$smtpServer = "companyemail.exchangemail.com"
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜