title: powershell: split the output and print after the select-string
body: <p>First of all, this is my first time with powershell. Everything is quite new. My script looks something like this.</p>
  
  <pre><code>$SMTPServer = "smtp.gmail.com"
  $SMTPPort = "587"
  $Username = "username@domain.com"
  $Password = "password"
  
  $to = "Username @domain.com"
  
  $subject = "daily_check"
  $body = (Get-Content 'C:\Users\xyz\Downloads\mylog.log' | Select-String 'string.string1.string2 - Request:') | Out-String
  
  $message = New-Object System.Net.Mail.MailMessage
  $message.subject = $subject
  $message.body = $body
  $message.to.add($to)
  #$message.cc.add($cc)
  $message.from = $username
  #$message.attachments.add($attachment)
  
  $smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
  $smtp.EnableSSL = $true
  $smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
  $smtp.send($message)
  </code></pre>
  
  <p>I get a successful email with all the lines with search string and It looks something like below. </p>
  
  <pre><code>INFO    2018-06-01 06:03:01,855 string.string1.string2 - Request: QWERTY- 123 Request: abc- XX1343XX123-01 Request: Type- BB
  INFO    2018-06-01 11:06:54,551 string.string1.string2 - Request: QWERTY- 123 Request: abc- XX-12573XX123-00 Request:  Type- BB
  INFO    2018-06-01 11:51:50,124 string.string1.string2 - Request: QWERTY- 123 Request: abc- 123XX122233-03 Request:  Type- BB
  INFO    2018-06-01 12:20:15,076 string.string1.string2 - Request: QWERTY- 123 Request: abc- XX-12563XX123-00 Request:  Type- BB
  INFO    2018-06-01 12:24:25,233 string.string1.string2 - Request: QWERTY- 123 Request: abc- XX-123XX12913-00 Request:  Type- BB
  </code></pre>
  
  <p>But I am expecting my output to look something like this below.</p>
  
  <pre><code>2018-06-01 06:03:01, QWERTY- 123 abc- XX1343XX123-01 Type- BB
  2018-06-01 11:06:54, QWERTY- 123 abc- XX-12573XX123-00 Type- BB
  2018-06-01 11:51:50, QWERTY- 123 abc- 123XX122233-03 Type- BB
  2018-06-01 12:20:15, QWERTY- 123 abc- XX-12563XX123-00 Type- BB
  2018-06-01 12:24:25, QWERTY- 123 abc- XX-123XX12913-00 Type- BB
  </code></pre>
  
  <p>I was using <code>-split ' '</code> and trying to convert each string as a variable and use them but I couldn't. Even if I did there should be a better method to do this. Any help is appreciated. Thanks.</p>