1

I have a powershell script that sends an email with some windows events.

$array contains the events

$array = (Get-WinEvent -FilterXml ([xml](Get-Content C:\SendMail\EventBackup.xml))| Format-List) | out-string

and then in the body of the email, I used to type $Body=$array and my report was like:

TimeCreated  : 3/16/2015 2:12:52 AM
ProviderName : Microsoft-Windows-Backup
Id           : 14
Message      : Backup completed.

TimeCreated  : 3/16/2015 2:12:52 AM
ProviderName : Microsoft-Windows-Backup
Id           : 4
Message      : Backup finished successfully.

TimeCreated  : 3/16/2015 1:00:14 AM
ProviderName : Microsoft-Windows-Backup
Id           : 1
Message      : Backup started.

I have changed the email type to HTML, so I can customize the report, but now the body is like:

TimeCreated : 3/19/2015 2:23:00 AM ProviderName : Microsoft-Windows-Backup Id : 14 Message : Backup completed. TimeCreated : 3/19/2015 2:23:00 AM ProviderName : Microsoft-Windows-Backup Id : 4 Message : Backup finished successfully. TimeCreated : 3/19/2015 1:00:13 AM ProviderName : Microsoft-Windows-Backup Id : 1 Message : Backup started.

All in the same line.

I know it's maybe because this lines:

$emailMessage.IsBodyHtml = $true
$emailMessage.Body = @"$array "@

How can I make it look like before in HTML?

1
  • 1
    Try trading that format-list | out-string for ConvertTo-HTML -As List and see if it doesn't look better. Commented Mar 19, 2015 at 12:38

1 Answer 1

1

try to convert new line to <br/>

$array=$array -replace '\n','<br/>' 
$emailMessage.Body = @"$array "@

after you comment : you can use the same technic to put, say the time created, in bold :

$array=$array -replace "(Timecreated .*?)(ProviderName)", '<strong>$1</strong>'   
Sign up to request clarification or add additional context in comments.

1 Comment

Dude, i freaking Love you. Thanks a lot. Did exatly what i needed. Can i do the same comand to edit TimeCreated to bold or change color?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.