正在尝试将回车添加到powershell脚本中



这是我的第一个powershell脚本,它工作得很好,它可以找到30分钟前的文件并通过电子邮件发送结果,我只想添加一个回车,这样输出更可读。

输出如下所示:J: \folder\lap001\testfile J:\folder\lap01\testfile2 J:\folder \lap001/testfile3 J:\folder-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添加一个换行符,而不是

最新更新