Sorting hashtable
Posted: Thu Jan 21, 2021 11:56 pm
Hello,
in my test environment i searching for all send and received mails on an exchange server to get the total size and total items on a daily basis. All is working fine. But when i display the results, they are in a wrong order. How can i change the order so that the oldest one is the first entry?
Here a short view from the output i get:
in my test environment i searching for all send and received mails on an exchange server to get the total size and total items on a daily basis. All is working fine. But when i display the results, they are in a wrong order. How can i change the order so that the oldest one is the first entry?
Code: Select all
$daycounter = 1
$SendReceivedMailsDaysOutput = Do
{
$dayendcounter = $daycounter - 1
$daystart = (Get-Date -Hour 00 -Minute 00 -Second 00).AddDays(-$daycounter)
$dayend = (Get-Date -Hour 00 -Minute 00 -Second 00).AddDays(-$dayendcounter)
$DayReceivedMails = $ReceivedMails | Where-Object {$_.timestamp -ge $daystart -and $_.timestamp -le $dayend}
$DaySendMails = $sendmails | Where-Object {$_.timestamp -ge $daystart -and $_.timestamp -le $dayend}
$daytotalsendmail = $daysendmails | measure-object Totalbytes -sum
$daytotalreceivedmail = $dayreceivedmails | measure-object Totalbytes -sum
$daytotalsendvol = $daytotalsendmail.sum
$daytotalreceivedvol = $daytotalreceivedmail.sum
$daytotalsendcount = $daytotalsendmail.count
$daytotalreceivedcount = $daytotalreceivedmail.count
$day = $daystart | get-date -Format "dd.MM.yy"
$daycounter++
$SendReceivedMailsDays = [ordered]@{
"Day" = $day
"Total send" = $daytotalsendcount
"Total send size ($($cmbSizeMailStat.Text))" = Convert-Size -Value $daytotalsendvol -From Bytes -To $($cmbSizeMailStat.Text) -Precision 2
"Total received" = $daytotalreceivedcount
"Total received size ($($cmbSizeMailStat.Text))" = Convert-Size -Value $daytotalreceivedvol -From Bytes -To $($cmbSizeMailStat.Text) -Precision 2
}
New-Object PsObject -Property $SendReceivedMailsDays
}
While ($daycounter -le $($nIntervallMailStat.Text))
Code: Select all
@{Day=21.01.21; Total send=0; Total send size (GB)=0; Total received=0; Total received size (GB)=0} @{Day=20.01.21; Total send=0; Total send size (GB)=0; Total received=0; Total received size (GB)=0} @{Day=19.01.21; Total send=0; Total send size (GB)=0; Tota
l received=0; Total received size (GB)=0} @{Day=18.01.21; Total send=0; Total send size (GB)=0; Total received=0; Total received size (GB)=0} @{Day=17.01.21; Total send=0; Total send size (GB)=0; Total received=0; Total received size (GB)=0}