如何发送电子邮件系统&应用程序事件日志位于同一电子邮件中
这段代码是每天通过电子邮件向我发送事件日志的错误,但是我如何将应用程序和事件日志放入其中?系统日志一起记录在一封电子邮件中吗?谢谢。
$emailFrom = "[email protected]"
$emailTo = "[email protected]"
$subject = "Daily Eventlog Errors"
$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
$message = New-Object Net.Mail.MailMessage($emailFrom, $emailTo, $subject, $emailbody)
$smtpServer = "companyemail.exchangemail.com"
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
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 = "[email protected]"
$emailTo = "[email protected]"
$subject = "Daily Eventlog Errors"
$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
$message = New-Object Net.Mail.MailMessage($emailFrom, $emailTo, $subject, $emailbody)
$smtpServer = "companyemail.exchangemail.com"
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是最新的帖子,但它是我在搜索脚本来执行此操作时所写的。
我冒昧地添加了自己的风格,并觉得我应该将其发布在这里:
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: