Bird
0
0

How can you combine pipeline object flow with sorting to list the top 3 largest files in a folder?

hard📝 Application Q9 of 15
PowerShell - Cmdlets and Pipeline
How can you combine pipeline object flow with sorting to list the top 3 largest files in a folder?
AGet-ChildItem | Select-Object -First 3 | Sort-Object Length -Descending
BGet-ChildItem | Where-Object Length -gt 3 | Sort-Object Length
CGet-ChildItem | Sort-Object Length -Descending | Select-Object -First 3
DGet-ChildItem | Sort-Object Length | Select-Object -Last 3
Step-by-Step Solution
Solution:
  1. Step 1: List files and sort by size descending

    Get-ChildItem lists files, Sort-Object Length -Descending sorts them largest first.
  2. Step 2: Select the first 3 largest files

    Select-Object -First 3 picks the top three after sorting.
  3. Final Answer:

    Get-ChildItem | Sort-Object Length -Descending | Select-Object -First 3 -> Option C
  4. Quick Check:

    Sort descending then select first 3 = Get-ChildItem | Sort-Object Length -Descending | Select-Object -First 3 [OK]
Quick Trick: Sort before selecting top items in pipeline [OK]
Common Mistakes:
  • Selecting before sorting
  • Using Where-Object incorrectly
  • Selecting last instead of first

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes