Question : Sorting a Powershell script output

I have a script that gets the size of folders in a share directory - but I want to sort it from largest to smallest and I cannot figure out how to sort it
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
function Get-Size($dir=".")
 
{
 
 
 
    $ds = get-item $dir | % { $f = $_;    get-childitem -r $_.FullName | measure-object -property length -sum -ErrorAction SilentlyContinue | select @{Name="Name";Expression={$f}},Sum}
 
    $ds | foreach-object { if ( $_.Sum -le 999KB) {$_.Sum = ([string]::Format("{0:#.##}",($_.Sum)/1KB)) + " KB" ; $_ } elseif ( $_.Sum -le 999MB) {$_.Sum = ([string]::Format("{0:#.##}",($_.Sum)/1MB)) + " MB" ; $_ } elseif ( $_.Sum -le 999GB) {$_.Sum = ([string]::Format("{0:#.##}",($_.Sum)/1GB)) + " GB" ; $_ }}
 
} # End Get-Size
 
# set Alias of 'du' for Get-Size
Set-Alias du Get-Size
 
Get-Size D:\IT\* > C:\Powershellscripts\Directorysize\itfoldersize.txt
Open in New Window Select All

Answer : Sorting a Powershell script output

/shrug It works for me on the three machines I tried against.

How are you calling the function?

Like this?
Get-Size c:\foldername
Random Solutions  
 
programming4us programming4us