正在尝试向powershell脚本添加回车符

正在尝试向powershell脚本添加回车符,powershell,Powershell,这是我的第一个powershell脚本,它工作得很好,它可以找到30分钟前的文件并通过电子邮件发送结果,我只想添加一个回车符,以便输出更具可读性 输出如下所示: J:\folder\lap001\testfile J:\folder\lap001\testfile2 J:\folder\lap001\testfile3 J:\folder\lap002\testfile #Command to get list of folders with logfiles where the logfile

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

输出如下所示: J:\folder\lap001\testfile J:\folder\lap001\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"
当数组被转换为字符串时,它们只是插入了一个空格-加入一个换行符