Find the busiest processes
Documentation: Microsoft Learn
Return the two processes with the highest cumulative CPU time.
An example to inspect
Preview the example. Sign in for the full lesson and activities.
Get-Process | Sort-Object CPU -Descending | Select-Object -First 2Scenario: Slow server
Inspect accumulated CPU time to find candidates for further investigation. One snapshot does not prove which process is causing a slowdown now.
Get process objects
Use
Get-Processto retrieve process objects and their properties.Sort CPU descending
Use
Sort-Object CPU -Descendingto put the largest values first.Keep the first two
Select-Object -First 2keeps the first two objects in the sorted result.
Hint
Commands in a pipeline pass objects, not display rows. Filter and sort before formatting.
Why sort before selecting?
Choose an answer, then check your reasoning.
Read the full exercise notes
Target
Return the two processes with the highest cumulative CPU time, highest first. CPU is measured in seconds, not percent.
Expected result
MsMpEng, chrome
Try the task
Show a worked solution
Reveal one approach
Try it in the lab
Write your pipeline below and run it against the fictional sample data, then check your result against the expected answer.
Follow the objects
Run the command to inspect each stage.
PowerShell skills
Process objects · Sorting · Selection · Descending order
Build the answer in three decisions
Read the pipeline from left to right. Each stage receives objects from the stage before it.
Collect
Get-Process
Start with 5 fictional process objects. Keep them as objects so later stages can inspect their properties.
Shape
Sort-Object CPU -Descending
Apply the condition or ordering required by the task. Sort CPU in descending order before selecting the first two objects.
Verify
Check order and returned names
The fixture should return MsMpEng, chrome. Order matters for this exercise.
Reason through the pipeline
The source stage returns 5 process objects. Then the pipeline applies Sort-Object CPU -Descending, Select-Object -First 2 without converting the objects to display text. That keeps the Name property available for the checker and for any later pipeline stage.
Why common attempts fail
Do not select the first rows before sorting when the task asks for a highest, lowest, first, or reverse-ordered result. Use Select-Object after the important filtering or ordering work; selecting too early can discard properties needed by later stages.
What the checker accepts
The evaluator runs the supported subset against the same fictional fixture. It expects MsMpEng, chrome. The returned order is part of the answer. Equivalent supported syntax is accepted.
Verify another attempt
First run Get-Process by itself and inspect the fixture. Then add one stage at a time and compare how many objects remain. This isolates the stage that changes the result and makes the final pipeline easier to explain and debug.