在Powershell中转换哈希表 [英] Converting Hashtable in Powershell
本文介绍了在Powershell中转换哈希表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一些将哈希表输出到电子邮件正文的帮助.
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@email.com" -from "Automated Reboot<no-reply@email.com>" -subject "E-Mail HashTable Test" -body ($table | Out-String) -smtpserver smtpserver.email.com
如果我刚返回了$ table,则消息正文看起来应该是
The Message body looks like it should if i just returned the $table
理想情况下,我希望将表格转换为看起来像具有适当列和标题的CSV格式,但我不想通过电子邮件将其作为附件发送.
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.
有人知道我该怎么做吗?我什至会考虑将其转换为HTML,以便在电子邮件中看起来不错.
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.
推荐答案
使用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
用于HTML:
[PSCustomObject]$table | convertto-html
这篇关于在Powershell中转换哈希表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文