Sorting

gwmi   Win32_PerfFormattedData_PerfProc_Process  | where { $_.Name -ne "_Total" -and $_.Name -ne "Idle"} | select name,@{Name='RAM';Expression={(($_.WorkingSetPrivate)/1MB).ToString("#.##")}} | Sort-Object ram -Descending |  select -first 5

the sorting is not giving me the right output , any suggestions?


9.141
81.785
81.102
8.91
8.328
August 27th, 2015 11:16am

Hi,

sure, you sort after converting it to string, so it will sort alphabetically. Switch the order and sort for WorkingSetPrivate first, then do the select and it should be just fine.

Cheers,
Fred

Free Windows Admin Tool Kit Click here and download it now
August 27th, 2015 11:22am

cool, thanks it works, i am banging my head on another issue, task manager showing 26% memory for firefox, but by this calculation i get only 13%, task manager doesnt know maths. 790 MB in 6GB is close to 13 % but why it is showing as 26% , MS bugs me a lot
August 27th, 2015 11:33am

i got the answer for this as well...it calculates total process memory not physical memory..
Free Windows Admin Tool Kit Click here and download it now
August 27th, 2015 11:39am

For the sorting issue, you can ensure numerical instead of alphabetical sorting by converting values to integers inside the sort-cmdlet:

... | sort{[int]$_.ram} -descending | ...

This convertion is for sorting only and not given to the next pipeline position or final output.

August 27th, 2015 12:28pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics