【问题标题】:how to email system & application eventlogs in the same email如何在同一封电子邮件中通过电子邮件发送系统和应用程序事件日志
【发布时间】:2017-01-29 18:38:17
【问题描述】:

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

$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-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)

【问题讨论】:

    标签: powershell powershell-2.0


    【解决方案1】:
    $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
    

    【讨论】:

      【解决方案2】:

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

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

      $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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-01-07
        • 1970-01-01
        • 2014-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多