Windows Batch with Powershell Send-MailMessage NoLine Breaks

October 8, 2020 at 23:16:35
Specs: Windows Server 2008 R2 Standard
Hi

I have a windows batch file that calls another windows batch file, then calls a powershell send-mailmessage command depending on the results, however the Send-MailMessage appears to be stripping half of the line breaks when it is displayed in the email. We are using Outlook 2013 I believe & I'm currently testing on Windows Server 2008 R2 Standard.

I've opened the results file in Notepad++ & I can see the carriage return & line feed symbols at the end of every line (CR & LF) & it displays fine in Notepad++. I even commented out the call to the 2nd batch file & just manually created another results file (eg: line 1 line 2 etc on multiple lines) but it displays fine when it is emailed yet the results file generated from calling the 2nd batch file does not.

Any ideas please?

Here is an example of what it looks like

@REM Prepares a log file that is to be used as the body of an email.
call "C:\SCRIPTS\find_exceptions.bat" 1>C:\SCRIPTS\results.log 2>&1

IF %errorlevel% EQU 0 (
	echo No exceptions found, no email required.
	exit /b 0
)

powershell -ExecutionPolicy ByPass -Command Send-MailMessage -SmtpServer mail.domain.net -To dummy@domain.com -From dummy2@domain.com -Subject 'My Subject' -Body ("Get-Content -Path C:\SCRIPTS\results.log | Out-String" ) 

message edited by Shell_L_D


See More: Windows Batch with Powershell Send-MailMessage NoLine Breaks

Related Solutions


Ask Question