title: Log Monitoring of Multiple Computers with Email Notification - Filter by EventID
body: <p>I have this PowerShell code below that gathers eventlogs from a list of computers and then sends email to the recipients. </p>
  
  <p>What i do need is for it to look for specific set of event id and not search for all events. Then if it sees any of the event i specified, it will send the report to the user else it would just end and not send any email.</p>
  
  <pre><code># Continue even if there are errors 
  $ErrorActionPreference = "Continue";
  
  # EMAIL PROPERTIES 
   # Set the recipients of the report. 
    $rcpts = "user@domain.com" 
  
  # REPORT PROPERTIES 
   # Path to the report 
    $reportPath = "SomePath"; 
  
   # Report name 
    $reportName = "SomeFileName"; 
  
  # Path and Report name together 
  $logReport = $reportPath + $reportName 
  
  # Get computer list to check logs 
  $computers = 'servers.txt'
  
  # Date coverage of logs to be monitored
  $StartDate = (get-date).AddDays(-1)
  
  # LogNames to be monitored
  $logname = "System"
  
  # Cleanup old files.. 
  $Daysback = "-7" 
  $CurrentDate = Get-Date; 
  $DateToDelete = $CurrentDate.AddDays($Daysback); 
  Get-ChildItem $reportPath | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item; 
  
  # CSS style
  $css= "&lt;style&gt;"
  $css= $css+ "BODY{ text-align: center; background-color:white;}"
  $css= $css+ "TABLE{    font-family: 'Lucida Sans Unicode', 'Lucida Grande', Sans-Serif;font-size: 12px;margin: 10px;width: 100%;text-align: center;border-collapse: collapse;border-top: 7px solid #004466;border-bottom: 7px solid #004466;}"
  $css= $css+ "TH{font-size: 13px;font-weight: normal;padding: 1px;background: #cceeff;border-right: 1px solid #004466;border-left: 1px solid #004466;color: #004466;}"
  $css= $css+ "TD{padding: 1px;background: ##FFFFFF;border-right: 1px solid #004466;border-left: 1px solid #004466;color: #669;hover:black;}"
  $css= $css+  "TD:hover{ background-color:#e5f7ff;}"
  $css= $css+ "&lt;/style&gt;" 
  
  # Process logs 
  $body = Get-Content $computers | ForEach-Object {
      Get-WinEvent -ComputerName $_ -FilterHashtable @{logname=$logname; Level=1,2,3; starttime=$StartDate}    
  }
  
  if ($body)
  {
      # Convert to HTML style 
      $body | ConvertTo-HTML -Head $css MachineName,LogName,LevelDisplayName,ID,TimeCreated,Message &gt; $logReport
  
      # Get-Date for Email Subject
      $subjectDate = get-date -format F
  
      # EMAIL Properties
      $smtpServer = "smtp.domain.com" 
        $smtp = New-Object Net.Mail.SmtpClient($smtpServer) 
        $msg = New-Object Net.Mail.MailMessage 
        $msg.To.Add($rcpts) 
              $msg.From = "user@domain.com" 
        $msg.Subject = "EventLog Report for $subjectDate" 
              $msg.IsBodyHTML = $true 
              $msg.Body = get-content $logReport 
        $smtp.Send($msg) 
              $body = "Hello"
  }
  </code></pre>