powershell - How to explode a Dictionary List as headers in a format-table -


updated include listing blank/empty properties objects

sorry title, not sure how label question. want express list of dictionary objects key header/property , value header's/property's value.

for example take following posh code

$obj1 = new-object object | select data; $obj1.data = @{"header1"="value1";"header2"="value2";} $obj2 = new-object object | select data; $obj2.data = @{"header1"="valuea";"header2"="valueb";} $obj3 = new-object object | select data; $obj3.data = @{"header1"="value1";"header3"="valuec";}  $tmp = @($obj1,$obj2,$obj3) 

$tmp looks following:

data                        ----                         {header2, header1} {header2, header1} {header3, header1} 

$tmp | select -expand data gets following useful information

name                           value    ----                           -----        header2                        value2 header1                        value1 header2                        valueb header1                        valuea header3                        valuec header1                        value1 

anyway can pivot data , turn names properties (or headers) , express them values i.e.

header1                        header2               header3 ----                           -----                 ----- value1                         valueb valuea                         value2 value1                                               valuec 

note: i've been able writing function takes each object in dictionary list, creates new object , adds properties via add-member, it's expensive , slow process when have thousands of entries , thousands of dictionary keys

since powershell v2 new-object has property parameter lets enter hash table in keys names of properties , values property value.

$tmp | select -expand data | %{new-object psobject -property $_} 

gives:

header2                                                     header1 -------                                                     ------- value2                                                      value1 valueb                                                      valuea 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -