New-udtable -data $data

Hello,

I would like to know how the process works inside the new-udtable and how it decides how to order the columns by itself.

For example, I have a script that reads diskspace from a server that needs to show 6 results and I want the columns to be in a specific order.

The order in my pscumtomobject :

ServerName, DriveLetter, VolumeName, TotalSpaceGB, FreeSpaceGB, PercentageFree.

This is the order I want my colums to be shown.
When I leave up to the udtable it will sort of randomise it into:

VolumeName ServerName TotalSpaceGB DriveLetter PercentageFree FreeSpaceGB

what I want is this:

So long story short, why does udtable work like this? can I use commando’s within udtable to make a choice how the order is? (besided using a udtablecolumn?)

thank you!

Hi there @ArjanKetting , I cant tell you how the automatic column choice is made specifically (it feels a bit like when you pass a list of hashtable vs CustomObject to Format-Table, so my guess is that the objects are being converted under the hood) , but I can tell you how I’ve seen this done and used it here

In the New-UDTable call if you specify the Columns then that’s the display order - and how you control sorting and filtering

If you provide table columns like this you’ll be able to control the order: Table | PowerShell Universal

I’ve taken to doing this in all tables at this point to get the column ordering I want and can then do sort/filter/etc as well