PowerShell, how to maintain the column orders of the returns

Answered PowerShell, how to maintain the column orders of the returns

  • Thursday, February 14, 2013 3:06 PM
     
      Has Code

    Hi, 

    I'm using PowerShell to return a two-dimension grids, and I was not able to have the returned columns to be in the order that I want. Any solution to this please?

    Basically, what I did is:

    $properties = @{item1='';item2='';...etc}
    $newVal = New-Object PSObject -Property $properties
    $newVal.item1=...
    $results += $newVal

    Then "return $results" at the end of the function. 

    Please help. 

    Thanks.

All Replies

  • Thursday, February 14, 2013 3:10 PM
    Moderator
     
     Answered

    Hashtables, by definition, are not ordered. To get a specific order, 1) don't use hashtables, or 2) output the object then use select-object to select the properties you want in the order you want.

    Bill

    • Marked As Answer by smetah Thursday, February 14, 2013 3:16 PM
    •