Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - How to sort a hashtable?

Reply
 
Old 01-31-2008   #1 (permalink)
Tibor Soos


 
 

How to sort a hashtable?

A have a hashtable:

PS I:\> $hash = @{ aaa = "one"; bbb = "two"; ccc = "three"}
PS I:\> $hash

Name Value
---- -----
bbb two
aaa one
ccc three

How can I get it sorted by Name?
--
Tibor

My System SpecsSystem Spec
Old 01-31-2008   #2 (permalink)
Tom Moreau


 
 

Re: How to sort a hashtable?

Try:

$hash.GetEnumerator() | sort-object name

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau


"Tibor Soos" <TiborSoos@xxxxxx> wrote in message
news:ECAC8108-1853-408A-8301-8B9B671B6B59@xxxxxx
A have a hashtable:

PS I:\> $hash = @{ aaa = "one"; bbb = "two"; ccc = "three"}
PS I:\> $hash

Name Value
---- -----
bbb two
aaa one
ccc three

How can I get it sorted by Name?
--
Tibor

My System SpecsSystem Spec
Old 01-31-2008   #3 (permalink)
Tibor Soos


 
 

Re: How to sort a hashtable?

Thanks! That works.
Could you explain me, why this does not work without the ".GetEnumertor()"?
What this function really do?

--
Tibor


"Tom Moreau" wrote:
Quote:

> Try:
>
> $hash.GetEnumerator() | sort-object name
>
> --
> Tom
>
> ----------------------------------------------------
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
> SQL Server MVP
> Toronto, ON Canada
> https://mvp.support.microsoft.com/profile/Tom.Moreau
>
>
> "Tibor Soos" <TiborSoos@xxxxxx> wrote in message
> news:ECAC8108-1853-408A-8301-8B9B671B6B59@xxxxxx
> A have a hashtable:
>
> PS I:\> $hash = @{ aaa = "one"; bbb = "two"; ccc = "three"}
> PS I:\> $hash
>
> Name Value
> ---- -----
> bbb two
> aaa one
> ccc three
>
> How can I get it sorted by Name?
> --
> Tibor
>
>
My System SpecsSystem Spec
Old 01-31-2008   #4 (permalink)
Tom Moreau


 
 

Re: How to sort a hashtable?

Check out:

http://www.microsoft.com/technet/scr...pstip0914.mspx

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau


"Tibor Soos" <TiborSoos@xxxxxx> wrote in message
news:64B1A95C-4534-4FA7-BD8E-FB35DC83F69E@xxxxxx
Thanks! That works.
Could you explain me, why this does not work without the ".GetEnumertor()"?
What this function really do?

--
Tibor


"Tom Moreau" wrote:
Quote:

> Try:
>
> $hash.GetEnumerator() | sort-object name
>
> --
> Tom
>
> ----------------------------------------------------
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
> SQL Server MVP
> Toronto, ON Canada
> https://mvp.support.microsoft.com/profile/Tom.Moreau
>
>
> "Tibor Soos" <TiborSoos@xxxxxx> wrote in message
> news:ECAC8108-1853-408A-8301-8B9B671B6B59@xxxxxx
> A have a hashtable:
>
> PS I:\> $hash = @{ aaa = "one"; bbb = "two"; ccc = "three"}
> PS I:\> $hash
>
> Name Value
> ---- -----
> bbb two
> aaa one
> ccc three
>
> How can I get it sorted by Name?
> --
> Tibor
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
array or hashtable PowerShell
Re: Can I sort within a sort, in folder view (eg., Name, Date) Live Mail
Sort by name doesnt sort correctly in my opinion Vista file management
Filter a hashtable? PowerShell
Sorting a hashtable PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46