title: Powershell script get event logs and if message contais string send email
body: <p>I'm still pretty green with PS and I'm stuck with a script. The end goal is to send an email if an event is logged in the application log by a certain source with a certain id (2 in this case) and if the message in the event contains a certain string. I had this working without a loop up until I realized the source that creates these events sometimes dumps 4 or 5 events at the exact same time all with the same id and since my old script was only looking at the newest event, it wouldn't find it if the event wasn't the last one logged in the 4 or 5 events dumped at once. So now the plan is to pull the last 10 id 2 events when a event id 2 is logged and parse through them looking for the needed string. And this is where everything is breaking for me. So far I have as a test:</p>
  
  <pre><code>    $eventLogs = Get-EventLog -LogName Application -Source "&lt;source&gt;" -InstanceId 2 -Newest 100 -EntryType Error
      $eventLogs | ForEach-Object Message
      if (Message -contains "&lt;string&gt;")
      {
       Write-Host "Found One"
      }
  </code></pre>
  
  <p>I've also Tried this:</p>
  
  <pre><code>    $eventLogs = Get-EventLog -LogName Application -Source "&lt;source&gt;" -InstanceId 2 -Newest 100 -EntryType Error | ForEach-Object Message
      foreach ($event in $eventLogs)
      {
      if(($eventLogs) -contains "&lt;string&gt;")
       {
        write-host "found one"
       }
      }
  </code></pre>
  
  <p>All to no avail. Can someone help me see what I'm missing?</p>