Reputation: 45135
PowerShell 3.0 gave us PSCustomObject as a type which allows proper table formatting, like this:
> [PSCustomObject]@{ Day = "Monday"; Task = "Wash car" }
Day Task
--- ----
Monday Wash car
But if I go via a variable, it reverts to stupid mode.
> [PSCustomObject]$row = @{ Day = "Monday"; Task = "Wash car" }
> $row
Name Value
--- ----
Task Wash car
Day Monday
Why? (thanks)
Upvotes: 1
Views: 923
Reputation: 45135
Solved it almost immediately.
[PSCustomObject]$row = [PSCustomObject]@{ Day = "Monday"; Task = "Wash car" }
Effectively, I was creating and casting a hashtable to a PSCustomObject. Still not entirely sure why the hashtable keys aren't turned into properties like a .NET 4.0 DLR ExpandoObject.
Much better to write CmdLets in C#.
Upvotes: 1