我想使用PowerShell输出一些表格,然后通过电子邮件将其发送给前/后内容在电子邮件中显示为“System.String []”。其余的内容似乎很好,如果我输出HTML字符串到控制台,一切都看起来很好。转换为HTML输出的前/后内容显示为System.String []而不是实际内容
function Send-SMTPmail($to, $from, $subject, $smtpserver, $body) {
$mailer = new-object Net.Mail.SMTPclient($smtpserver)
$msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
$msg.IsBodyHTML = $true
$mailer.send($msg)
}
$Content = get-process | Select ProcessName,Id
$headerString = "<table><caption> Foo. </caption>"
$footerString = "</table>"
$MyReport = $Content | ConvertTo-Html -fragment -precontent $headerString -postcontent $footerString
send-SMTPmail "my Email" "from email" "My Report Title" "My SMTP SERVER" $MyReport
在我的电子邮件显示为:
System.String[]
ProcessName Id
... ...
System.String[]
做一个彻头彻尾文件,然后一个Invoke项具有相同的结果发送电子邮件...
你已经救了我的理智。 Out-String,FTW。 – JakeRobinson 2011-02-09 22:47:43