title: Find pattern with Powershell and send email
body: <p>I have a script that searches through xml files for a pattern and then a file is created with the results.  It then emails the file when the search finds a match.  However, this part is not working.  Any help would(or tweaks) would be amazing:</p>
  
  <pre><code>$date= Get-Date -Format yyyyMMdd
  $dir= "c:\test\$date"
  $path=Get-ChildItem -Path $dir -Recurse
  $pattern = "&lt;RESULT&gt;FAILED&lt;/RESULT&gt;"
  $submitted = select-string -path $path -pattern $pattern | select Path,Filename | Export-Csv -Path "D:\Failed.csv"
  if(@($submitted).Count -eq 0) {
  ##donothing 
  }
  else
             {
      Send-MailMessage -From "noreply@email.com" -To users@email.com -Subject "Failed Report" -Body "Attached are the failed files for App" -Attachments "D:\Failed.csv" -SmtpServer 0.0.0.0
      Remove-Item "D:\Failed.csv" -recurse
             }
  </code></pre>