Are there any PowerShell guru's here?
Are there any PowerShell guru's here?
Author
Discussion

TheAngryDog

Original Poster:

13,323 posts

240 months

Tuesday 3rd July 2018
quotequote all
I have a script that is using a text file as an input. This script runs and is checking against the files mentioned in the input file to see if they're over a certain size. If they are, it lists these in an email and sends to me. The problem is, is that it will not put the files on a new line, despite having `n in the line;

Instead of the output looking like this;

file
file
file

It looks like this;

file file file

If I put a ; in the line, it puts that at the end of the last file, like this;

file file file;

I am baffled.

It is this part of the script;

"The following files have exceeded 28GB`n$datas`n "

Any ideas?

Harpoon

2,554 posts

245 months

Tuesday 3rd July 2018
quotequote all
Email client ignoring the line feed? Does using 'r 'n (carriage return & LF) help?

TheAngryDog

Original Poster:

13,323 posts

240 months

Tuesday 3rd July 2018
quotequote all
Harpoon said:
Email client ignoring the line feed? Does using 'r 'n (carriage return & LF) help?
Doesn't make a different.

Email client is Outlook 2016.

benjeffrey

84 posts

131 months

Tuesday 3rd July 2018
quotequote all
You'll need to use the -BodyAsHTML cmdlet in your Powershell script, like below:

Send-MailMessage -BodyAsHTML

Then you can specify line breaks between the files using HTML like this

<br />

If you want anymore help, would need to see the contents of the script.

TheAngryDog

Original Poster:

13,323 posts

240 months

Tuesday 3rd July 2018
quotequote all
benjeffrey said:
You'll need to use the -BodyAsHTML cmdlet in your Powershell script, like below:

Send-MailMessage -BodyAsHTML

Then you can specify line breaks between the files using HTML like this

<br />

If you want anymore help, would need to see the contents of the script.
No dice I am afraid frown

$datas=Get-Content c:\temp\dbfcheck\dblist.txt | Get-Item | Where-Object {($_.Length /1GB) -gt '1'}
if($datas.Length -gt 0) {
$AdminName = "email@domain.com"
$Pass = Get-Content "c:\temp\dbfcheck\info.txt" | ConvertTo-SecureString
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $Pass
Send-MailMessage -From email@domain.com -To email@domain.com -subject "Table has exceeded 1GB" -BodyAsHTML "The following files have exceeded 1GB <br />$datas<br />" -SmtpServer smtp.office365.com -Credential $cred -UseSsl -Port 25
}

This is what it puts out;

The following files have exceeded 28GB
d:\path\file.dbf d:\path\file.dbf d:\path\file.dbf

This is the input file;

d:\path\file.dbf
d:\path\file.dbf
d:\path\file.dbf
d:\path\file.dbf

benjeffrey

84 posts

131 months

Tuesday 3rd July 2018
quotequote all
Try swapping out for this -

$HTML = "The following files have exceeded 1GB<br /><br />"
$datas | ForEach-Object {$HTML += "$_<br />"}

Send-MailMessage -From email@domain.com -To email@domain.com -subject "Table has exceeded 1GB" -BodyAsHTML $HTML -SmtpServer smtp.office365.com -Credential $cred -UseSsl -Port 25

TheAngryDog

Original Poster:

13,323 posts

240 months

Tuesday 3rd July 2018
quotequote all
benjeffrey said:
Try swapping out for this -

$HTML = "The following files have exceeded 1GB<br /><br />"
$datas | ForEach-Object {$HTML += "$_<br />"}

Send-MailMessage -From email@domain.com -To email@domain.com -subject "Table has exceeded 1GB" -BodyAsHTML $HTML -SmtpServer smtp.office365.com -Credential $cred -UseSsl -Port 25
Legend! This has got them on different lines, thank you very much for your help with this!! I have been fighting it for ages!