rafvasq
rafvasq

Reputation: 1522

Outputting CSV to String/Table

I have a CSV with data that is to be emailed to me at the end of a powershell script. I know that I can attach the CSV file to the email itself, but I'd like to know how to output the data from the CSV straight into the body, formatted properly. I assume that this would involve converting the CSV to a String or something.

I've tried things like ConvertTo-Csv along with Format-Table, but this comes up without formatting. I've thought of looping through the csv line-by-line but I'm not sure where to go from there.

Upvotes: 0

Views: 185

Answers (1)

TechSpud
TechSpud

Reputation: 3518

You need to use ConvertTo-Html

$body = $YOUR_CSV_DATA | ConvertTo-Html -Fragment

Send-MailMessage -To '[email protected]' -From '[email protected]' -Subject 'Your report' -BodyAsHtml -Body $body -SmtpServer 'smtp.example.com'

Upvotes: 1

Related Questions