[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Get line breaks in powershell output to email

Posted on 2013-10-23
5
Medium Priority
?
6,498 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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…

649 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