尝试添加回车到powershell脚本

尝试添加回车到powershell脚本

问题描述:

这是我的第一个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; 

确定应该不会太难此行

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

后添加另一条线,让您的换行分隔符的文本

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

当数组被转换为字符串时,它们只是插入一个空格。 -join改为添加换行符

+0

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