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

enter image description here

is possible output in powershell more aligned.

enter image description here

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','&nbsp;') <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','&nbsp;') <br/>"})</font>" 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -