Are there any PowerShell guru's here?
Discussion
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?
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?
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 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.

$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
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
$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
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!$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
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff


