user3391373
user3391373

Reputation: 55

Power shell new line in email body

I have currently this script and it works fine :

    $Path = "C:\test\log\trace.log"
Write-Output "before delete"> $Path 
(Get-ChildItem "C:\TestMail\test\test1" -Recurse | 
    Select-Object -ExpandProperty Fullname) >> $Path  
(Get-ChildItem "C:\TestMail\test\test1" -Recurse | 
  Where-Object {$_.LastWriteTime -ge (Get-Date).addDays(-1)} |
    Remove-Item -Force) >> $Path
Write-Output "preserved"  >> $Path
(Get-ChildItem "C:\TestMail\test\test1" -Recurse | 
    Select-Object -ExpandProperty Fullname) >> $Path
$body = Get-Content -Path $PATH -Raw

Problem is that i receive single string results in body when im using Send-MailMessage in power shell.

How to get new lines for each string that i receive in body?

Thanks!

Upvotes: 0

Views: 142

Answers (1)

user3391373
user3391373

Reputation: 55

Ive did it!

$body =  Get-Content $Path |%{ "$_`n" }|Out-String

I put this and send it as regular -body $body via Send-MailMessage

Upvotes: 2

Related Questions