TechNet-Gallery icon indicating copy to clipboard operation
TechNet-Gallery copied to clipboard

Transpose-Object bug

Open scriptingstudio opened this issue 3 years ago • 3 comments

This does not work

[pscustomobject]@{a=0; b=1; c=2},
[pscustomobject]@{a=3; b=4; c=5},
[pscustomobject]@{a=6; b=7; c=8},
[pscustomobject]@{a=9; b=10; c=11} | Transpose-Object

but if you add $col=1 to begin block and replace $InputObject | Out-String (line 50) with "column$($col)"; $col++ it will

scriptingstudio avatar Oct 08 '22 21:10 scriptingstudio

Hello @scriptingstudio,

I took me some time to find where a bug is. Your example works fine with Transpose-Object, you might see it better when you add Format-Table:

[pscustomobject]@{a=0; b=1; c=2},[pscustomobject]@{a=3; b=4; c=5},[pscustomobject]@{a=6; b=7; c=8},[pscustomobject]@{a=9; b=10; c=11} | Transpose-Object | Format-Table

There seems to be a bug in Out-GridView, when a key starts oder ends with white space, Out-GridView does not determine the value, for example see this:

[pscustomobject]@{ "a "=1 } | Out-GridView

This one works:

[pscustomobject]@{ "a"=1 } | Out-GridView

Is this the issue you found? I will implement a workaround for this.

Greetings

Markus

MScholtes avatar Oct 09 '22 14:10 MScholtes

image

scriptingstudio avatar Oct 09 '22 15:10 scriptingstudio

Property
         a b c                                             a b c                       a b c                    a  b  c
         - - -                                             - - -                       - - -                    -  -  -
         0 1 2                                             3 4 5                       6 7 8                    9 10 11



-------- --------------------------- --------------------------- --------------------------- --------------------------
a                                                              3                           6                          9
b        1                                                     4                           7                         10
c        2                                                     5                           8                         11

scriptingstudio avatar Oct 09 '22 15:10 scriptingstudio

Hello @scriptingstudio,

I do not know if it's really what you expect but I uploaded a new version of Transpose-Object.ps1 today that has a workaround for the Out-GridView error (remove leading or trailing whitespace from titles) and fixes an error. Additionally you can select the property whose values are used as titles. If the object do not have a title property the script still uses the text representation of the objects as titles.

Greetings

Markus

MScholtes avatar Nov 24 '22 15:11 MScholtes

I would expect to see this 200px-Matrix_transpose

or in Powershell

[pscustomobject]@{'a'=0; 'b'=1; 'c'=2}
a b c
- - -
0 1 2

[pscustomobject]@{'a'=0; 'b'=1; 'c'=2} | Transpose-Object
Property value
-------- -----
a        0
b        1
c        2

but I see this

[pscustomobject]@{'a'=0; 'b'=1; 'c'=2} | Transpose-Object
Property a b c
         - - -
         0 1 2
-------- -------------------
a
b        1
c        2

but

[pscustomobject]@{'a'=0; 'b'=1; 'c'=2} | Transpose-Object -ti a
Property 0
-------- -
a
b        1
c        2

I understand that this is your way, but it is not math way.

scriptingstudio avatar Nov 25 '22 03:11 scriptingstudio

Hello @scriptingstudio,

an answer to keep these thread alive.

Being mathematically correct the expected result would be something like

a 0
- -
b 1
c 2

But this was not my intension (since maths does not define how to transpose objects), I saw the practival use for Out-GridView and Export-CSV.

Greetings

Markus

P.S.: The 0 is missing because 0 is equated to $NULL

MScholtes avatar Nov 28 '22 16:11 MScholtes

I think this can be closed

MScholtes avatar Jan 03 '23 16:01 MScholtes