Disclaimer
This is my personal blog. The opinions and views I express are my own. The information I provide is on an as-is basis. I make no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this blog and will not be liable for any errors, omissions, or delays in this information or any losses, injuries or damages arising from its use.

PowerShell Basics: Sorting and Selecting Objects with Sort-Object and Select-Object

 

# Selecting
#Default
Get-Process

# All Properties
Get-Process | Select-Object -Property * | Out-GridView

# Sorting
# Changes the default sorting order for Get-Process
Get-Process | Sort-Object CPU

# Minimize the data and sort
Get-Process | Select-Object ProcessName, CPU | Sort-Object CPU -Descending

## Caution 
# Mission: Get the top 10 processes by CPU usage (which 10 processes have the most CPU usage)
Get-Process | 
    Select-Object ProcessName, CPU -First 10 | 
    Sort-Object CPU -Descending

# or

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

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.