title: Get Specific Strings from File and Store in Variable
body: <p>My sample log looks like :</p>
  <pre><code>2022-09-01 23:13:05Z | error | 2022-09-02 02:13:05 - [Task] Id:120 Name:OPT_VIM_1HEAD Exception with index:18 | 18.9251137 | Exception:
  ERROR       connection to partner '10.19.101.17:3300' broken
  2022-09-01 23:13:25Z | error | 2022-09-02 02:13:25 - [Task] Id:121 Name:OPT_VIM_1ITEM 
  ERROR       connection to partner '10.19.101.22:3300' broken
  2022-09-01 23:13:25Z | error | 2022-09-02 02:13:25 - [Task] Id:121 Name:OPT_VIM_1ITEM RunId:7 Task execution failed with error: One or more errors occurred., detail:
  ERROR       connection to partner '10.19.101.22:3300' broken
  </code></pre>
  <p>I want to extract the job name OPT_VIM_1HEAD or OPT_VIM_1ITEM (its dynamic) and also the timestamp after the &quot;error&quot; pattern : 2022-09-02 02:13:25 or 2022-09-02 02:13:05 in different variables.</p>
  <p>I have also written the script as :</p>
  <pre><code>$dir = 'C:\ProgramData\AecorsoftDataIntegrator\logs\'
  $StartTime = get-date
  $fileList = (Get-ChildItem -Path $dir -Filter '2022-09-02.log' | Sort-Object LastWriteTime -Descending | Select-Object -First 1).fullname
  $message =  Get-Content $fileList | Where-Object {$_ -like ‘*error*’}
  $message
  $details = Select-String -LiteralPath $fileList -Pattern 'error' -Context 0,14 | Select-Object -First 1 | Select-Object Path, FileName, Pattern, Linenumber
  $details[0]
  </code></pre>
  <p>But not able to retrieve the tokens mentioned above</p>