[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Get line breaks in powershell output to email

Posted on 2013-10-23
5
Medium Priority
?
6,945 Views
Last Modified: 2013-10-23
I have a text file that is being read by powershell that has varying number of lines in it. I want powershell to read the lines and output to an email that lists each line on its own line.

The script below emails the lines all as one line and Ihave not been able to get it to show the line breaks.

Any help would be greatly appreciated.

$Line = Get-Content E:\MonitorFolder\PingResults.txt | Out-String  
 
  Send-MailMessage -From 'Lost_Network_Connection@company.com' -To 'me@systrends.com' `
  -SmtpServer 'smtp.company.com' `
  -Subject 'Lost Network Connection' `
  -BodyAsHtml `
    -Body @"
      $(($Line) + "'n")  
"@
0
Comment
Question by:jimmylew52
  • 3
  • 2
5 Comments
 
LVL 41

Expert Comment

by:footech
ID: 39594326
Try the following.
$Line = Get-Content E:\MonitorFolder\PingResults.txt 
 
  Send-MailMessage -From 'Lost_Network_Connection@company.com' -To 'me@systrends.com' `
  -SmtpServer 'smtp.company.com' `
  -Subject 'Lost Network Connection' `
  -BodyAsHtml `
  -Body ($Line -join "`n")

Open in new window

0
 
LVL 1

Author Comment

by:jimmylew52
ID: 39594385
Two lines in PingResults.txt

server is down
Station is down

Displays in email as :

server is downstation is down

instead of two lines.

 -Body ($Line -join "`n")  --  does the same thing.
0
 
LVL 41

Expert Comment

by:footech
ID: 39594457
Oh wait, just noticed that you're outputting HTML.  One moment.
0
 
LVL 41

Accepted Solution

by:
footech earned 2000 total points
ID: 39594493
Make sure you're not piping to Out-String in line 1.
Change line 7 to
  -Body ($Line -join "<br>")

Open in new window

0
 
LVL 1

Author Closing Comment

by:jimmylew52
ID: 39594646
That worked!!!   Thank You!!!
0

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Screencast - Getting to Know the Pipeline

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question