0

我需要一些帮助,将哈希表输出到电子邮件正文。

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

$table = @{

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

} 

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

如果我刚刚返回 $table,消息正文看起来应该

理想情况下,我希望将表格转换为具有适当列和标题的 CSV 格式,但我不想将其作为附件通过电子邮件发送。

有谁知道我该怎么做?我什至会考虑将其转换为 HTML,以便在电子邮件中看起来不错。

4

1 回答 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
于 2013-10-18T18:27:19.997 回答