Why does a column in a PowerShell table disappear if I sort in the reverse order?

I want to create a table of process names and total processor time, sorted by the total processor time. The following works as expected:

ps | sort -p cpu | select processname,cpu 

But if I reverse the sort direction as follows, the processor time columns disappear:

 ps | sort -descending -p cpu | select processname,cpu 

Why is this?

It seems that the CPU property is sometimes Double, and sometimes null. When I ran the first command, the first element had a zero CPU, and the column was displayed: for the second command, the first element has a two-digit CPU, but the column is not displayed.

When a column is not displayed, it still exists! Using Format-List, display it, for example:

 ps | sort -descending -p cpu | select processname,cpu | fl 

What's happening?

+4
source share
2 answers

try it

 ps | sort -descending -p cpu | select processname,cpu | Format-Table -AutoSize 
+5
source

The properties of the first object in the result set determine the columns to be displayed. Any response that forces a column into the first returned result displays a column for all returned results.

0
source

All Articles