[英]send-mailmessage replaces html style tags with System.String[]
I am trying to use send-mailmessage
to send an email in powershell (v2). 我正在尝试使用
send-mailmessage
在powershell(v2)中发送电子邮件。
I run a MySQL Query, and convert it to html as follows: 我运行一个MySQL查询,并将其转换为html,如下所示:
$htmlbody = $mysqlresult | `
ConvertTo-Html -property field1, `
field2, `
field3 `
-pre "<style>table{border: 3px solid #000000;}</style>"
I then send an email as: 然后,我以以下方式发送电子邮件:
Send-MailMessage -to "$ToAddress" `
-From "$FromAddress" `
-Subject "Subject Line" `
-BodyasHtml "$htmlbody" `
-SmtpServer "$SMTP"
The email sends, and I get my email with the data in a table. 电子邮件发送后,我以表格的形式收到电子邮件。 But the ... section gets replaced with
System.String[]
但是...部分被
System.String[]
取代
As far as I can tell, there's no 'funny' characters in there. 据我所知,那里没有“有趣”的字符。 Can anyone explain why this is?
谁能解释为什么?
Select your properties before piping the objects into ConvertTo-Html
: 在将对象
ConvertTo-Html
到ConvertTo-Html
之前,请选择属性。
$htmlbody = $mysqlresult |
select field1, field2, field3 |
ConvertTo-Html -Pre '<style>...</style>'
Depending on what datatype of the fields actually have you may need to mangle string arrays into strings first, for instance via calculated properties . 根据实际具有的字段的数据类型,您可能需要首先将字符串数组修改为字符串,例如,通过计算属性 。 Example:
例:
$htmlbody = $mysqlresult |
select field1, field2, @{n='field3';e={$_.field3 -join ' '}} |
ConvertTo-Html -Pre '<style>...</style>'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.