title: Reading date and time from a text file using powershell Get-Content
body: <p>I have a text file which contains the last update of a Log file.</p>
  
  <pre><code> Volume in drive E is ISCSI
   Volume Serial Number is XXXXXX
  
   Directory of E:\Apps\LOGS
  
  02/26/2020  11:39 AM           762,661-vx_02262020.log
                 1 File(s)        762,661 bytes
                 0 Dir(s)  12,554,166,272 bytes free
  </code></pre>
  
  <p>I am using the below powershell script to read the content and email the same:</p>
  
  <pre><code>$Date = (Get-Date -format "MMddyyyy")
  
  $body = Get-Content -path C:\Desktop\Logs\LOG_TIME_$Date.txt -raw
  
  Send-MailMessage -To "abc@gmail.com2" -From "abc@gmail.com"  -Subject "LOG TIME $Date" -Body "$body" -SmtpServer "xxxxx.main.glb.corp.local"
  </code></pre>
  
  <p>The code works fine and sends all the content of the files in the body to my email. But i only want the date and time (which will keep changing) to be sent in the email.</p>
  
  <p>I have tried lot of options, but none of which seems to work:</p>
  
  <ul>
  <li>used | select-string "05/"</li>
  <li>used Where-Object</li>
  <li>used -Pattern '$Date' -AllMatches |</li>
  </ul>
  
  <p>Can someone help me how to populate only date and time in the email body from the text file  ?</p>