PowerShell v3 - Bringing [ordered] to your hashtables
*****Warning. This is from a preview release******
When using a hashtable in PowerShell v2 the insertion order is not preserved. So I might be slightly OCD, but this bugs me:
$HashTableOld = @{a=1; b=2; c=3; d=4}
$HashTableOld
If you consider the type of the object you will see that it is of .NET type System.Collections.Hashtable
$HashTableOld | Get-Member
In PowerShell v3 it is now possible to create an ordered hashtable using the [ordered] syntax
$HashTableNew = \[ordered\]@{a=1; b=2; c=3; d=4}
$HashTableNew
This will create an object of .NET type System.Collections.Specialized.OrderedDictionary
$HashTableNew | Get-Member
Possibly the most significant takeaway from this change is that it came as a feature suggestion from the community. Using http://connect.microsoft.com/PowerShell anybody can submit bugs / feature requests and gather community support for them via voting them up.If you have a good idea, then suggest it - you never know, it might make it into the product!
This feature suggestion came from Diogenus, more details can be found here.