2015-04-03 112 views
0

這是我的第一個powershell腳本,它工作的很好,它發現30分鐘的文件,併發送電子郵件的結果,我只是想添加回車,所以輸出更多可讀。嘗試添加回車到powershell腳本

輸出看起來像這樣: j:\文件夾\ lap001 \ testfile的Y:\文件夾\ lap001 \ testfile2 Y:\文件夾\ lap001 \ testfile3 Y:\文件夾\ lap002 \ testfile的

#Command to get list of folders with logfiles where the logfile is at least 30 minutes old. 
$varlogfile = Get-ChildItem -Path "j:\folder" -Recurse -Include "testfile*" | Where-Object {$_.LastWriteTime -le ((Get-Date).AddMinutes(-30))} 

#Email setup 
$SMTPServer = "server" 
$From = "Administrator" 
$To = "something" 
$Subject = "A Logfile older than 30 minutes has been detected" 
$Body = "Logfile(s) older than 30 minutes have been detected in the following folders: 

$varlogfile 

Please login and attempt to process the files manually, if the manual process fails, open a ticket with something. 

From the Admin 
" 

#Command to send email 
Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer 

exit 0; 

回答

0

確定應該不會太難此行

$varlogfile = Get-ChildItem -Path .... 

後添加另一條線,讓您的換行分隔符的文本

$varlogfile = $varlogfile -join "`r`n" 

當數組被轉換爲字符串時,它們只是插入一個空格。 -join改爲添加換行符

+0

非常感謝,完美的工作! – Sean 2015-04-03 15:38:47