Saturday, March 17, 2018

Format a Table

In this previous post, we used PowerShell to retrieve processes sorted by CPU:

Get-Process | Sort-Object CPU -Descending




And in this previous post, we winnowed down the list to just the top 10 processes taking CPU cycles:

Get-Process | Sort-Object CPU -Descending | Select-Object -First 10

 












  

But that might get us more information than we really need. Handles? PM(K)? Is there a way to just display the process name and the CPU, while leaving out the extraneous data?

Sure. Just use Format-Table:

Get-Process | Sort-Object CPU -Descending | Select-Object `
 -First 10 | Format-Table Name, CPU -Autosize




We just pipe our data stream to Format-Table and identify which columns we want displayed. 

The -Autosize parameter lines up the columns neatly together. Try the command without the -Autosize parameter to see the difference. 


No comments:

Post a Comment