I have log file created from a batch process in the below format.
Step DateTime Description #0 09/12/2016 17:02:20 TestTableCount.ps1 started from step 1 #1 09/12/2016 17:02:21 The table etl.ProcessLog is Empty . Failed
I want to add this to the body of the email using Send-MailMessage
in PowerShell.
I wrote a code that converts the text file to HTML and adds it as a table in the body of the mail.
Code:
$body = Get-Content $LogFile | out-String
$body = $body -replace '^(\S+)\s+(\S+)\s+(\S+)', '<tr><th style = "border: 1px solid black; background: #dddddd; padding: 5px;">$1</th><th style = "border: 1px solid black; background: #dddddd; padding: 5px;">$2</th><th style = "border: 1px solid black; background: #dddddd; padding: 5px;">$3</th></tr>'
$body = $body -replace '\n(\S+)\s+(\S+)\s+(\S+)', '<tr><td style = "border: 1px solid black; padding: 5px;">$1</td><td style = "border: 1px solid black; padding: 5px;">$2</td><td style = "border: 1px solid black; padding: 5px;">$3</td></tr>'
$body = '<body><table style = "border: 1px solid black; border-collapse: collapse;">' + $body + '</table></body>'
But that is resulting in the below format:
I want the sate and time to come under the DateTime column, but from the code I have written I am getting the time under Description.
How to correct this and get the proper format?