如何发送电子邮件系统&应用程序事件日志位于同一电子邮件中

发布于 2024-10-17 01:08:33 字数 874 浏览 3 评论 0原文

这段代码是每天通过电子邮件向我发送事件日志的错误,但是我如何将应用程序和事件日志放入其中?系统日志一起记录在一封电子邮件中吗?谢谢。

$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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遮云壑 2024-10-24 01:08:33
$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
$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
妖妓 2024-10-24 01:08:33

这不是最新的帖子,但它是我在搜索脚本来执行此操作时所写的。

我冒昧地添加了自己的风格,并觉得我应该将其发布在这里:

$emailFrom = "[email protected]"
$emailTo = "[email protected]"
$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)

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 = "[email protected]"
$emailTo = "[email protected]"
$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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文