2011-09-22 106 views
2

我有一個來自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 

Script代碼:

$report2_tail = Get-Content .\backup2.log)[-12 .. -1] 
$encoding = [System.Text.Encoding]::UTF8 
Send-mailmessage -Smtpserver smtp.server.address -encoding $encoding -from "Backup-Replication<[email protected]>" -to "[email protected]" -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 

什麼是一個最好的方法解決這個問題 ? 問候 馬辛

回答

3

管道獲取內容結果到輸出字符串的cmdlet:

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