开发者

Text array to email body

开发者 https://www.devze.com 2023-04-06 11:40 出处:网络
I have a backup log file from robocopy and would like to take last lines from that file and send it as email body.

I have a backup log file from robocopy and would like to take last lines from that file and send it as email body. Log example:

            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

Script code:

$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
"

Script works fine but the message body is in one line and looks like this:

Total    Copied   Skipped  Mismatch    FAILED    Extras      Dirs :     85262     85257         1         0         4         0     Files :    637048    637047         0     开发者_JAVA百科    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

What is a best way to solve the problem ? Regards Marcin


Pipe Get-Content result to the Out-String cmdlet:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号