Skip to content

Latest commit

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..

PowerShell - PSObject property order (ordered hash tables)

How to change property order during PSObject output?

$Properties=@{
a=1b=2c=3
}
$Object=New-Object-TypeName PSObject -Property $Properties
$Object
c b a
- - -
3 2 1

What if you need a,b and then c property order?

$Properties=@{
a=1b=2c=3
}
$Object=New-Object-TypeName PSObject -Property $Properties
$Object | select a,b,c
a b c
- - -
1 2 3

Or even simpler, just add [Ordered] before @{
Note: I am not sure but it seems to be working since .Net 4.0 or something like that.

$Properties= [Ordered]@{
a=1b=2c=3
}
$Object=New-Object-TypeName PSObject -Property $Properties
$Object
a b c
- - -
1 2 3