电子邮件正文的文本数组

时间:2011-09-22 09:57:17

标签: text powershell

我有来自robocopy的备份日志文件,并希望从该文件中获取最后一行并将其作为电子邮件正文发送。 记录示例:

            Total    Copied   Skipped  Mismatch    FAILED    Extras
 Dirs :     85262     85257         1         0         4         0
Files :    637048    637047         0         0         1         0
Bytes :1558.929 g1558.929 g         0         0       165         0
Times :  19:30:49  19:01:06                       0:00:00   0:29:43

Speed :            24448224 Bytes/sec.
Speed :            1398.938 MegaBytes/min.

Ended : Wed Sep 21 15:42:01 2011

脚本代码:

$report2_tail = Get-Content .\backup2.log )[-12 .. -1]
$encoding = [System.Text.Encoding]::UTF8
Send-mailmessage  -Smtpserver smtp.server.address -encoding $encoding -from "Backup-Replication<backup@mm.com>" -to "mm@mm.com" -subject "End of Replication Report" -body  "
backup Replication Report
------------------------------------------------------------
$report2_tail
"

脚本工作正常,但邮件正文在一行中,如下所示:

Total    Copied   Skipped  Mismatch    FAILED    Extras      Dirs :     85262     85257         1         0         4         0     Files :    637048    637047         0         0         1         0     Bytes :1558.929 g1558.929 g         0         0       165         0     Times :  19:30:49  19:01:06                       0:00:00   0:29:43      Speed :            24448224 Bytes/sec.     Speed :            1398.938 MegaBytes/min.      Ended : Wed Sep 21 15:42:01 2011

解决问题的最佳方法是什么? 问候 马尔钦

1 个答案:

答案 0 :(得分:3)

将Get-Content结果传递给Out-String cmdlet:

$report2_tail = Get-Content .\backup2.log )[-12 .. -1] | Out-String
Send-mailmessage ... -subject "End of Replication Report" -body $report2_tail 
相关问题