powershell - Convertto-HTML outputting pre/post content showing up as System.String[] instead of actual content -


i trying use powershell output table pre/post content , email it, pre/post content showing in email "system.string[]." rest of content seems fine, , if output html string console, looks fine.

function send-smtpmail($to, $from, $subject, $smtpserver, $body) {     $mailer = new-object net.mail.smtpclient($smtpserver)     $msg = new-object net.mail.mailmessage($from,$to,$subject,$body)     $msg.isbodyhtml = $true     $mailer.send($msg) }  $content = get-process | select processname,id $headerstring = "<table><caption> foo. </caption>" $footerstring = "</table>" $myreport = $content | convertto-html -fragment -precontent $headerstring -postcontent $footerstring  send-smtpmail "my email" "from email" "my report title" "my smtp server" $myreport 

shows in email as:

system.string[] processname id ...             ... system.string[] 

doing out-file , invoke-item has same results sending email...

convertto-html returns list of objects - strings , string arrays e.g.:

407# $headerstring = "<table><caption> foo. </caption>" 408# $footerstring = "</table>" 409# $content = get-date | select day, month, year 410# $myreport = $content | convertto-html -fragment -precontent $headerstring `                                            -postcontent $footerstring 411# $myreport | foreach {$_.gettype().name} string[] string string string string string string string string string string[] 

so $myreport contains array of both strings , string arrays. when pass array mailmessage constructor, expects type string, powershell attempts coerce string. result is:

412# "$myreport" system.string[] <table> <colgroup> <col/> <col/> <col/> </colgroup> <tr><th>day </th><th>month</th><th>year</th></tr> <tr><td>9</td><td>2</td><td>2011 </td></tr> </table> system.string[] 

the easy solution run output of converto-html through out-string cause $myreport single string:

413# $myreport = $content | convertto-html -fragment -precontent $headerstring `                                            -postcontent $footerstring |                             out-string 414# $myreport | foreach {$_.gettype().name} string 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -