Formatting Table to send in email having columns aligned


$myformat = @{expression={$_.acno};label="acno";width=25}, @{expression={$_.name};label="name";width=25}, @{expression={$_.status};label="status";width=150}
$result = $myhashtable | format-table $myformat -wrap | out-string
---
hi, have hash-table ($myhashtable) contains 3 column (acno, name, status) , few rows of values columns. need send result in email. 1st column (acno) contains same amount of digits therefore 2nd column gets aligned correctly, 2nd column contains different amount of characters (0..25), 3rd column values not aligned , moved either left or right. column-name not aligned. if change width each column, change position proportionally remains messedup. tried several ways format not helped.

acno            name       status

056590900  alex g.      active

056590920  fred andersson    active

056590964  mats active


appreciated.






as mjolinor indicated, using html reliable way.

this isn't elegant method, align the columns in received email...

$result = $myhashtable | select acno,name,status | convertto-html -head 'business process'

then use -bodyashtml parameter of send-mailmessage.

other create custom html display your data the way want to.

the problem truetype fonts... every character has it's own width, , spaces use less width else, makes aligning text tricky.

hope helps.

btw: that's array creating, not hash table.

$myhashtable.gettype()

get-help about_hash_tables


just humble sysadmin




Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Group Policy Event ID 1058 Error Code 1326 (The user name or password is incorrect)

Suspicious event log Event ID: 4905

DCOM received error "2147746132" from...