title: Powershell extract log file content for last n minutes
body: <p>I am trying to extract content from a log file for last n minutes and perform another set of actions based on the extracted data. My Log file look like below:</p>
  
  <pre><code>2019-01-25 02:45:55,018 [5 - -22d] INFO Server - Some information
  2019-01-25 02:45:55,018 [5 - -22d] INFO Server - Some information
  2019-02-25 02:45:55,018 [5 - -22d] INFO Server - Some information
  2019-02-25 19:09:50,018 [5 - -22d] ERROR IOException Some Error
  2019-02-25 02:45:55,018 [5 - -22d] INFO Server - Some information
  </code></pre>
  
  <p>I have created a task scheduler which runs every say 1 minute and checks the log file for the specific error in last 1 minute and performs the next action.What matters here is the time, I want to compare the current time with the log file time when the error occurred. What I have tried is below:</p>
  
  <pre><code> $data=Get-Content $log | Select-String -Pattern 'String to search error'
     foreach ($line in $data){
       $logdate = Get-Date ($line -split ',')[0] -Format 'yyyy-MM-dd HH:mm'
        Write-Output $logdate
         if($date -eq $logdate){
            Write-Output "Some action"          
         }   
     }
  </code></pre>
  
  <p>Is there a better way to achieve the same results? Can the community shed some light as I am not much familar with powershell? Also tried various other cmdlets "LastWriteTime, Get-Content, regex-, etc"</p>