0

I need some help outputting a a hash table to the body of an email message.

$computer = "adwte998"
$err = "This is the error"
$td = Get-Date

$table = @{

Workstation = $computer
Error = $err
Time = $td

} 

send-mailmessage -to "[email protected]" -from "Automated Reboot<[email protected]>" -subject "E-Mail HashTable Test" -body ($table | Out-String) -smtpserver smtpserver.email.com

The Message body looks like it should if i just returned the $table

I would ideally like to convert the table to a format that looks like a CSV with the proper columns and headers but I don't want to email it as an attachment.

Does anyone know how i can go about doing this? I would even considering converting it to HTML so it looks nice in the email.

1 Answer 1

1

Using V3:

$computer = "adwte998"
$err = "This is the error"
$td = Get-Date

$table = [ordered]@{
Workstation = $computer
Error = $err
Time = $td
} 

[PSCustomObject]$table | ft -auto | out-string

Workstation Error             Time                 
----------- -----             ----                 
adwte998    This is the error 10/18/2013 1:26:08 PM

for HTML:

[PSCustomObject]$table | convertto-html
Sign up to request clarification or add additional context in comments.

2 Comments

Ok, that solves the formatting of the table if I were to output it on the screen but I wanted to convert it to HTML now so I can use the -BodyAsHtml in Send-MailMessage. How would I do that?
Added example for converting to html

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.