I have populated a powershell dictionary as given below.
$test=New-Object System.Collections.Generic.Dictionary"[String,String]"
$test.Add("1.0.0.0", "A");
$test.Add("2.0.0.0", "A");
$test.Add("1.1.0.0", "B");
$test.Add("1.1.1.0", "C");
$test.Add("1.2.0.0", "B");
$test.Add("2.1.0.0", "B");
$test.Add("1.1.2.0", "C");
When i debugged the code in PowerGui editor i can see the $test value as given below
I want to sort the dictionary on the base of Keys. So the resultant out put should come as below.
{[1.0.0.0,A],[1.1.0.0,B],[1.1.1.0,C],[1.1.2.0,C],[1.2.0.0,B],[2.0.0.0,A],[2.1.0.0,B]}
So for performing the sort on the base of keys and also for looping through the sorted dictionary i used the below code. But unfortunately neither the sort nor the looping not works for me.
$test=$test.GetEnumerator() | sort -Property Keys
while ($test.MoveNext())
{
Write-Host $test.Key + " --> "
+ $test.Value
}
The resultant dictionary after performing the GetEnumerator is given below.
SO basically i have two requirement.
1.)Sort the dictionary on the base of keys
2.)Loop through the sorted dictionary