email - Send mail body with Robocopy Summary in powershell -
i using powershell send mail robocopy summary sheduled task.
below powershell version details
name value ---- ----- psversion 5.1.15063.502 psedition desktop pscompatibleversions {1.0, 2.0, 3.0, 4.0...} buildversion 10.0.15063.502 clrversion 4.0.30319.42000 wsmanstackversion 3.0 psremotingprotocolversion 2.3 serializationversion 1.1.0.1
my script below,
$pw = get-content .\bumblebee.txt | convertto-securestring $cred = new-object system.management.automation.pscredential "xyz\abc", $pw $cont = gc c:\users\vinod_dmse\desktop\bat\backup_log_20170816.log -last 12 |%{"$_ <br/>"}|out-string $encoding = [system.text.encoding]::utf8 send-mailmessage -smtpserver smtp.xyz.com -to "abc@xyc.com" -credential $cred -from "backupkr.alert@xyz.com" -subject " backup alert" -bodyashtml $cont"
this works,
but when i'm getting mail body text alignment issues.
below output
is possible output in powershell more aligned.
thanks in advance,
as ansgar alludes to, issue because of how html handles spaces. multiple spaces created spacebar, tab key , return key ignored when write code. html interprets them whitespace between words, , displays single space.
so 2 possible solutions either use <pre>
tag, stands preformatted text. in context of script this:
$cont = "<pre>$(get-content c:\users\vinod_dmse\desktop\bat\backup_log_20170816.log -last 12 | foreach-object {"$_ <br/>"})</pre>"
otherwise replace regular spaces non-breaking spaces.
$cont = "$(get-content c:\temp\rblog.txt -last 12 | foreach-object {"$($_ -replace '\s',' ') <br/>"})"
also issue can using font uneven character widths. using <font>
tag font family each character same width text line better.
$cont = "<font face='monospace'>$(get-content c:\temp\rblog.txt -last 12 | foreach-object {"$($_ -replace '\s',' ') <br/>"})</font>"
Comments
Post a Comment