Hash tables in powershell

I am developing an application in PowerShell. I store variables in a hash table. How to keep order in a hash table? I want the order to be the same as me when I populated the hash table.

+5
source share
3 answers

Hash tables, by their nature, do not support the order of values. There are already several workarounds on the network. Check these

http://www.tellingmachine.com/post/2009/01/When-PowerShell-hash-table-magic-backfires.aspx

http://huddledmasses.org/powershell-and-hashtable-oddities/

Or try

PS C:\WINDOWS\system32> $OrderedList = New-Object System.Collections.Specialized.OrderedDictionary
PS C:\WINDOWS\system32> $OrderedList
PS C:\WINDOWS\system32> $OrderedList.Add("Name","Ravi")
PS C:\WINDOWS\system32> $OrderedList.Add("Age","30")
PS C:\WINDOWS\system32> $OrderedList

Name                           Value
----                           -----
Name                           Ravi
Age                            30
+8
source

Hashtables . , , , System.Collections.Specialized.OrderedDictionary.

+2

All Articles