Hi
i`m pretty newbie in this field,
I need to Import-Csv pipe it to ConvertTo-Html (RTL Hebrew table) Send-MailMessage it
Embedd as body TO = multiple recipients
Script location:
c:\daily\lastfilebydate.csv
Reciptient:
test1@domain.com
test2@domain.com
test3@domain.com
Exchange:
172.16.20.15
partial result achieved with the following syntax:
Import-Csv -Path c:\daily\lastfilebydate.csv | ConvertTo-Html -CssUri 'C:\design.css' | Out-File lastfilebydate.html -Encoding utf8
please help needed!
Olaf
June 9, 2020, 10:12pm
2
What kind of help do you need? Did you read the help for Send-Mailmessage? The rest is pretty straight forward.
Instead of outputting the converted CSV file to a file a assign it to a variable and use this variable to provide it to Send-MailMessage. The same for the list of your recipients.
Also, you don’t need the Exchange server information, you specifically need SMTP Relay information, which is name, port and if it not anonymous, then credentials permitted to send mail through the relay.
finally succeeded with the following syntax:
$mycsv = Import-Csv -Path z:\daily\08062020.csv | ConvertTo-Html -Head $style
$mailBody =
@"
$mycsv
"@
$style = "<style>BODY{font-family: Arial; font-size: 10pt; direction:rtl;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $style + "</style>"
Send-MailMessage -Body $mailBody -BodyAsHtml `
-From "admin@domain.com" -To "test1@domain.com" `
-Subject "Report Summery" -Encoding $([System.Text.Encoding]::UTF8) `
-SmtpServer "172.16.20.15"
now, how i change font/cell color based on negative value?
Thanks!
Olaf
June 10, 2020, 1:36pm
5
Please take a look at the section “Free Resources ” here on this site. There you find a free ebook “Creating HTML Reports in Windows PowerShell ”. It has everything you need.
BTW: You should not use backticks in your code. That’s considered a bad style.
Here’s a suggestion for a little bit cleaner stlye:
$mycsv = Import-Csv -Path z:\daily\08062020.csv | ConvertTo-Html -Head $style
$style = @'
<style>BODY{font-family: Arial; font-size: 10pt; direction:rtl;}
TABLE{border: 1px solid black; border-collapse: collapse;}
TH{border: 1px solid black; background: #dddddd; padding: 5px; }
TD{border: 1px solid black; padding: 5px; }
</style>
'@
$SendMailMessageParams = @{
Body = $mycsv
BodyAsHtml = $true
From = 'admin@domain.com'
To = 'test1@domain.com'
Subject = 'Report Summery'
Encoding = 'utf8'
SmtpServer = '172.16.20.15'
}
Send-MailMessage @SendMailMessageParams
thanks!
[quote quote=234802]$mycsv = Import-Csv -Path z:\daily\08062020.csv | ConvertTo-Html -Head $style
[/quote]
get error till add the | Out-String
$mycsv = Import-Csv -Path z:\daily\08062020.csv | ConvertTo-Html -Head $style | Out-String