title: How to scan SQL Server error log (and ignore some errors) with PowerShell?
body: <p>I need a PowerShell script (2.0 compatible) to scan SQL Server 2008 R2 and later error logs. I need to have a list of phrases to search for, and a list of phrases to exclude.</p>
  
  <pre><code>param ([String]$instanceName=$(throw "Instance name was not supplied"))
  
  [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO')|Out-Null;
  $sqlServer = new-object ("Microsoft.SqlServer.Management.Smo.Server") $instanceName;
  $r = $sqlServer.ReadErrorLog();
  
  $find = "Error:","Failed";
  $exclude = "Error: 0x2098";
  
  # need to do something with $r here and involve $find and $exclude
  </code></pre>
  
  <p>So, for example I want to find all lines in the ERRORLOG that contain <code>Error:</code> and <code>Failed</code>, but exclude the ones in the <code>$exclude</code> array. Any ideas?</p>