Converting txt file as HTML in Powershell Send-MailMessage -


i have log file created batch process in below format.

step datetime            description  #0   09/12/2016 17:02:20 testtablecount.ps1 started step 1 #1   09/12/2016 17:02:21 table etl.processlog empty . failed

i want add body of email using send-mailmessage in powershell.

i wrote code converts text file html , adds table in body of 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 resulting in below format:

this result code

i want sate , time come under datetime column, code have written getting time under description.

how correct , proper format?

date , time separated space, matched second \s+ in second regular expression.

change

$body = $body -replace '\n(\s+)\s+(\s+)\s+(\s+)', '<tr><td ...' 

to

$body = $body -replace '\n(\s+)\s+(\s+ \s+)\s+(\s+)', '<tr><td ...' 

and replacement should expect.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -