Hi,
I am populating a hastable at runtime using a loop. Once done, I try to sort the hastable by value (numeric data), it doesn't seem to work. Sorting by key (string data) works just fine.
I have tried almost everything but nothing seems to work.
Sharing the code below, any help will be appreciated.
$TextToWrite="<table border='1'><tr><th align='left'>Directory Name</th><th align='left'>Directory Size</th>"
$list = (Get-ChildItem $path | where-object {$_.PSIsContainer -eq $True})
$htSizes=$null
$htSizes=@{}
#$sizeForSort=0
foreach ($i in $list)
{
$size = (Get-ChildItem $i.FullName -recurse | measure-object -property length -sum | where {$_.sum -gt 500MB})
if($size.sum)
{
#$TextToWrite+="<tr><td>" + $i.FullName + "</td><td> -- {0:N2}" -f ($size.sum/1mb) + " MB</td></tr>"
#$htSizes.add($i.FullName,"{0:N2}" -f [int]($size.sum/1mb))
$htSizes.add($i.FullName,"{0:N2}" -f ($size.sum/1mb))
}
}
$htSizes.GetEnumerator() | sort-object -property value.SortOrder -descending
foreach($item in $htSizes)
{
$TextToWrite+="<tr><td>" + $item.name + "</td><td> -- {0:N2}" -f $item.value + " MB</td></tr>"
}
$TextToWrite+="</table>"
#echo $TextToWrite
Thanks!