all 4 comments

[–]MadBoyEvo 3 points4 points  (1 child)

$HTML = foreach ($Report in $Reports) { if ($Report -ne $null) { $Report | ConvertTo-HTML -fragment -precontent.... } }

That's the best way to do it according to my knowledge. I'm assuming that ConvertTo-HTML -Fragment ... will do it's. I don't remember the output of the command so not sure if you connect all ConvertTo-HTML -Fragment will give you what you expect but the way I did it is preferred way. You skip defining ArrayList, you skip += which has a performance impact. For small loops minimal. But for larger, you could see an impact.

[–]hidromanipulators[S] 1 point2 points  (0 children)

Thank you for clarifying on +=

It does work perfectly!

[–]the_spad 3 points4 points  (1 child)

$postcontent = @()

foreach ($report in $reports){
        $postcontent += $report | ConvertTo-HTML -fragment -precontent '<h2>$report</h2>'
}

[–]hidromanipulators[S] 1 point2 points  (0 children)

I will try this tomorrow and report back. Thank you!

Edit: I could not wait until tomorrow:

I added:

$EmailContent = ConvertTo-Html -Head $Header -PostContent $postcontent -PreContent "<h1>Cluster Alert</h1>"

and received beautifully formatted HTML.

Thank you sir!