Powershell发送邮件信息,如何把换行符放在bodyvariables中

我正在一个文件夹内的多个文件中search一个string。 如果我得到的string,然后我想电子邮件所有这些文件夹有这个string。 我已经想通了,并调整了我想要我的格式的方式。

问题是当我发送电子邮件时,内容全部出现在1行中。 我希望这个文字能被逐字打破。 以下是代码:

$find = Get-Childitem –Path C:\inetpub\wwwroot\*\Web.config | Select-String -Pattern "abc..config" $boards = $find.Path | Out-String [array]$split = $boards.Split("\") $count = $split.Count $out = for ($i=0; $i -le $count; $i++) { $split[$i+3] $i = $i + 3 } $out2 = $out | Out-String Send-mailmessage -from "" -to "" -subject "Test" -body $out2 -BodyAsHtml -priority High -dno onFailure -smtpServer 

问题是,身体出现如下:ABC ABC2

但是,我希望身体是:

 ABC ABC2 

我也尝试获得输出到一个文本文件,并与gci使用-Raw:

 $find = Get-Childitem –Path C:\inetpub\wwwroot\*\Web.config | Select-String -Pattern "abc..config" $boards = $find.Path | Out-String [array]$split = $boards.Split("\") $count = $split.Count $out = for ($i=0; $i -le $count; $i++) { $split[$i+3] $i = $i + 3 } $out | Out-file -FilePath C:\Test.txt $body = Get-content C:\Test.txt -Raw Send-mailmessage -from "" -to "" -subject "Test" -body $body -BodyAsHtml -priority High -dno onFailure -smtpServer 

我确实使用了Out-String和Raz,而且我在V4上。 不知道我缺less什么。 当我输出文件,这是正确的格式与换行符,但不是当我的电子邮件。 我宁愿不创build一个文本文件,只是在正文中使用该variables。

谢谢

您的邮件正文的内容不是HTML,但您正在-bodyAsHtml上使用-bodyAsHtml。 你的身体只是文本,当你指定-bodyAsHTML ,导致换行符被删除。 删除-bodyAsHtml应该可以解决你的问题。

在HTML文档中,换行符由<P><BR> ,并且只在出现在<PRE>中时才被保留。